/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //get all project inputs from the post $inputs = $request->all(); if ($inputs['color']) { /* * * Handle adding sort order to projects. "sort" * column in projects table. Get max sort # * then add 1 for the sort column value. * */ //gets the max order number from projects table. $max_project_sort = Project::max('order'); $order_number = null; if ($max_project_sort) { $order_number = $max_project_sort + 1; } else { $order_number = 1; } $project = new Project(); //this is a global way to access the auth class. $user = auth()->user(); $project->name = $inputs['name']; $project->color = $inputs['color']; $project->completed = 0; $project->user_id = $user->id; $project->order = $order_number; $project->save(); return redirect($inputs['referrer']); } else { } }