%PDF- %PDF-
Direktori : /home/silvzytp/crm-dub-code/app/Http/Controllers/Backend/ |
Current File : //home/silvzytp/crm-dub-code/app/Http/Controllers/Backend/CallingSubStatusController.php |
<?php namespace App\Http\Controllers\Backend; use Illuminate\Http\Request; use App\Models\CallingSubStatus; use App\Http\Controllers\Controller; use App\Models\CallingStatus; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; class CallingSubStatusController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { Gate::authorize('app.sub-status.index'); // page title page_title('Sub-Status'); $callingSubStatus = CallingSubStatus::with('callings','callingStatus')->latest('id')->get(); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Sub-Status'=>'']; return view('backend.pages.sub-status.index',['breadcrumb'=>$breadcrumb,'callingSubStatus'=>$callingSubStatus]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { Gate::authorize('app.sub-status.create'); // page title page_title('New Sub-Status'); $status = CallingStatus::where('status',1)->get(); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Sub-Status'=>route(routeName().'.sub-status.index'),'Create'=>'']; return view('backend.pages.sub-status.form',['breadcrumb'=>$breadcrumb,'status'=>$status]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'status' => 'required|integer', 'is_published' => 'required|in:1,2' ]); if ($request->has('sub_status')) { foreach ($request->sub_status as $key => $value) { CallingSubStatus::create([ 'user_id' => Auth::id(), 'status_id' => $request->status, 'name' => $value['name'], 'status' => $request->is_published ]); } } return redirect()->route(routeName().'.sub-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.sub-status.edit'); // page title page_title('Edit Sub-Status'); $callingStatus = CallingSubStatus::findOrFail($id); $status = CallingStatus::where('status',1)->get(); // breadcrumb $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Sub-Status'=>route(routeName().'.sub-status.index'),'Edit'=>'']; return view('backend.pages.sub-status.form',['breadcrumb'=>$breadcrumb,'callingStatus'=>$callingStatus,'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', 'is_published' => 'required|in:1,2', 'status' => 'required|integer' ]); CallingSubStatus::find($id)->update([ 'user_id' => Auth::id(), 'status_id' => $request->status, 'name' => $request->name, 'status' => $request->is_published ]); 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.sub-status.delete')) { CallingSubStatus::findOrFail($id)->delete(); $output = ['status'=>'success','message'=>ALERT_DELETE]; }else{ $output = UNAUTHORIZED; } return response()->json($output); } } }