Viewing file: UserPlanController.php (2.1 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers;
use App\Models\UserPlan; use Illuminate\Http\Request;
class UserPlanController extends Controller { public function index(){ $data['userPlans']=UserPlan::where('plan_id','!=',1)->orderBy('created_at','desc')->get(); return view('plans.user_plan',$data); }
public function status_change(Request $request){ if(env('APP_DEMO')){ return redirect()->back()->withErrors(['msg' => trans('layout.app_demo_message')]); } if ($request->status=='approved') { $id=$request->id; $userPlan=UserPlan::find($id);
if(!$userPlan) abort(404); $old_user_plan = UserPlan::where(['user_id' => $userPlan->user_id, 'is_current' => 'yes'])->firstOrFail(); $old_user_plan->is_current = 'no'; $old_user_plan->save();
$userPlan->status = 'approved'; $userPlan->is_current = 'yes'; $userPlan->save();
$old_user_plan->delete(); notification('plan',$userPlan->id,$userPlan->user_id,"Your plan has been approved");
return redirect()->back()->with('success', trans('layout.message.userplan_approve_success')); } elseif($request->status=='rejected') { $id=$request->id; $userPlan=UserPlan::find($id); $userPlan->status = 'rejected'; $userPlan->is_current = 'no'; $userPlan->save(); notification('plan',$userPlan->id,$userPlan->user_id,"Your plan has been rejected");
return redirect()->back()->with('success', trans('layout.message.userplan_reject_success')); } elseif ($request->status='pending'){ $id=$request->id; $userPlan=UserPlan::find($id); $userPlan->status = 'pending'; $userPlan->is_current = 'no'; $userPlan->save(); notification('plan',$userPlan->id,$userPlan->user_id,"Your plan has been changed to pending");
return redirect()->back()->with('success', trans('layout.message.userplan_status_change_msg')); } } }
|