%PDF- %PDF-
Direktori : /home/silvzytp/crm-dub-code/app/Http/Controllers/Backend/ |
Current File : //home/silvzytp/crm-dub-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; class CallingStatusController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { Gate::authorize('app.status.index'); // page title page_title('Status'); $callingStatus = CallingStatus::with('subStatuses')->latest('id')->get(); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Status'=>'']; return view('backend.pages.status.index',['breadcrumb'=>$breadcrumb,'callingStatus'=>$callingStatus]); } /** * 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,$id) { if ($request->ajax()) { if (Gate::allows('app.status.delete')) { CallingStatus::findOrFail($id)->delete(); $output = ['status'=>'success','message'=>ALERT_DELETE]; }else{ $output = UNAUTHORIZED; } return response()->json($output); } } }