Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Helpers\Helper;
- use App\Http\Requests\PlanRequest;
- use App\Models\Plan;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class PlanController extends Controller
- {
- public function index()
- {
- $plans = Plan::autoWhere()->autoSort()->autoPaginate();
- return view('admin.plans.index', compact('plans'));
- }
- public function create()
- {
- return view('admin.plans.form');
- }
- public function store(PlanRequest $request)
- {
- $input = $request->all();
- try {
- Plan::create($input);
- } catch (\Exception $e) {
- return Helper::throwError(Helper::msg('error.store'));
- }
- return Helper::throwSuccess(Helper::msg('create'), redirect(route('admin.plan.index')));
- }
- public function edit($id)
- {
- $plan = Plan::findOrFail($id);
- return view('admin.plans.form', compact('plan'));
- }
- public function update(PlanRequest $request, $id)
- {
- $input = $request->all();
- $plan = Plan::findOrFail($id);
- try {
- $plan->update($input);
- } catch (\Exception $e) {
- return Helper::throwError(Helper::msg('error.update'));
- }
- return Helper::throwSuccess(Helper::msg('update'), redirect(route('admin.plan.index')));
- }
- public function destroy($id)
- {
- $plan = Plan::findOrFail($id);
- try {
- $plan->delete();
- } catch (\Exception $e) {
- return Helper::throwError(Helper::msg('error.delete'));
- }
- return Helper::throwSuccess(Helper::msg('delete'));
- }
- public function restore($id)
- {
- $plan = Plan::withTrashed()->findOrFail($id);
- try {
- $plan->restore();
- } catch (\Exception $e) {
- return Helper::throwError(Helper::msg('error.restore'));
- }
- return Helper::throwSuccess(Helper::msg('restore'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement