コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required|min:5|max:60|unique:services', 'route' => 'required|max:60|unique:services']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $service = new Service();
     if ($request->sort_id > 0) {
         $service->sort_id = $request->sort_id;
     } else {
         $service->sort_id = $service->count() + 1;
     }
     $service->slug = !empty($request->slug) ? $request->slug : str_slug($request->title);
     $service->title = $request->title;
     $service->route = $request->route;
     $service->title_description = $request->title_description;
     $service->meta_description = $request->meta_description;
     $service->text = $request->text;
     if ($request->status == 'on') {
         $service->status = 1;
     } else {
         $service->status = 0;
     }
     $service->save();
     return redirect('/admin/services')->with('status', 'Сервис добавлен!');
 }