Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Admin;
  4.  
  5. use App\Helpers\Helper;
  6. use App\Http\Requests\PlanRequest;
  7. use App\Models\Plan;
  8. use Illuminate\Http\Request;
  9. use App\Http\Controllers\Controller;
  10.  
  11. class PlanController extends Controller
  12. {
  13.     public function index()
  14.     {
  15.         $plans = Plan::autoWhere()->autoSort()->autoPaginate();
  16.  
  17.         return view('admin.plans.index', compact('plans'));
  18.     }
  19.  
  20.     public function create()
  21.     {
  22.         return view('admin.plans.form');
  23.     }
  24.  
  25.     public function store(PlanRequest $request)
  26.     {
  27.         $input = $request->all();
  28.  
  29.         try {
  30.             Plan::create($input);
  31.         } catch (\Exception $e) {
  32.             return Helper::throwError(Helper::msg('error.store'));
  33.         }
  34.  
  35.         return Helper::throwSuccess(Helper::msg('create'), redirect(route('admin.plan.index')));
  36.     }
  37.  
  38.     public function edit($id)
  39.     {
  40.         $plan = Plan::findOrFail($id);
  41.  
  42.         return view('admin.plans.form', compact('plan'));
  43.     }
  44.  
  45.     public function update(PlanRequest $request, $id)
  46.     {
  47.         $input = $request->all();
  48.         $plan = Plan::findOrFail($id);
  49.  
  50.         try {
  51.             $plan->update($input);
  52.         } catch (\Exception $e) {
  53.             return Helper::throwError(Helper::msg('error.update'));
  54.         }
  55.  
  56.         return Helper::throwSuccess(Helper::msg('update'), redirect(route('admin.plan.index')));
  57.     }
  58.  
  59.     public function destroy($id)
  60.     {
  61.         $plan = Plan::findOrFail($id);
  62.  
  63.         try {
  64.             $plan->delete();
  65.         } catch (\Exception $e) {
  66.             return Helper::throwError(Helper::msg('error.delete'));
  67.         }
  68.  
  69.         return Helper::throwSuccess(Helper::msg('delete'));
  70.     }
  71.  
  72.     public function restore($id)
  73.     {
  74.         $plan = Plan::withTrashed()->findOrFail($id);
  75.  
  76.         try {
  77.             $plan->restore();
  78.         } catch (\Exception $e) {
  79.             return Helper::throwError(Helper::msg('error.restore'));
  80.         }
  81.  
  82.         return Helper::throwSuccess(Helper::msg('restore'));
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement