%PDF- %PDF-
Direktori : /home/silvzytp/ccd-ind-code/app/Http/Controllers/Backend/ |
Current File : //home/silvzytp/ccd-ind-code/app/Http/Controllers/Backend/CallingStatusController.php |
<?php namespace App\Http\Controllers\Backend; use Illuminate\Http\Request; use App\Models\CallingStatus; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; use Yajra\DataTables\Facades\DataTables; class CallingStatusController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { Gate::authorize('app.status.index'); if($request->ajax()){ $getData = CallingStatus::with('subStatuses'); return DataTables::eloquent($getData) ->addIndexColumn() ->filter(function ($query) use ($request){ if (!empty($request->search_text)) { $query->where('name', 'LIKE',"%{$request->search_text}%"); } }) ->addColumn('status', function($row){ return status($row->status); }) ->addColumn('action', function($row){ $action = '<div class="d-flex align-items-center justify-content-end">'; if (Gate::allows('app.status.edit')) { $action .= '<a class="btn-style btn-style-edit ml-1" href="'.route(routeName().'.status.edit',$row->id).'"><i class="fa fa-edit"></i></a>'; } if (Gate::allows('app.status.delete')) { if ($row->subStatuses->isEmpty()) { $action .= '<button class="btn-style btn-style-danger deletable-btn ml-1" data-title="Do you really want to delete this record?" data-id="'.$row->id.'"><i class="fa fa-trash"></i></button>'; }else{ $action .= ''; } } $action .= '</div>'; return $action; }) ->rawColumns(['status','action']) ->make(true); } // page title page_title('Status'); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Status'=>'']; return view('backend.pages.status.index',['breadcrumb'=>$breadcrumb]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { Gate::authorize('app.status.create'); // page title page_title('New Status'); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Status'=>route(routeName().'.status.index'),'Create'=>'']; return view('backend.pages.status.form',['breadcrumb'=>$breadcrumb]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'name' => 'required|string|unique:calling_statuses,name', 'status' => 'required|in:1,2' ]); CallingStatus::create([ 'user_id'=> Auth::id(), 'name' => $request->name, 'status' => $request->status ]); return redirect()->route(routeName().'.status.index')->with('success',ALERT_SUCCESS); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { Gate::authorize('app.status.edit'); // page title page_title('Edit Status'); $status = CallingStatus::findOrFail($id); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Status'=>route(routeName().'.status.index'),'Edit'=>'']; return view('backend.pages.status.form',['breadcrumb'=>$breadcrumb,'status'=>$status]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $request->validate([ 'name' => 'required|string|unique:calling_statuses,name,'.$id, 'status' => 'required|in:1,2' ]); CallingStatus::find($id)->update([ 'user_id'=> Auth::id(), 'name' => $request->name, 'status' => $request->status ]); return back()->with('success',ALERT_UPDATE); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request) { if ($request->ajax()) { if (Gate::allows('app.status.delete')) { CallingStatus::findOrFail($request->data_id)->delete(); $output = ['status'=>'success','message'=>ALERT_DELETE]; }else{ $output = UNAUTHORIZED; } return response()->json($output); } } }