/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, \App\Menu $menu, \App\Category $category)
 {
     $validation = \Validator::make($request->all(), ['name' => 'min:3']);
     if ($validation->fails()) {
         return response($validation->errors()->all(), 400);
     }
     if ($category->accessable($menu)) {
         $category->update($request->all());
         $category->savePhoto($request->file('photo'));
         return $category;
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, \App\Menu $menu, \App\Category $category)
 {
     $validation = \Validator::make($request->all(), ['name' => 'required|min:3', 'price' => 'required|integer|min:1']);
     if ($validation->fails()) {
         return response($validation->errors()->all(), 400);
     }
     if ($category->accessable($menu)) {
         $food = new \App\Food($request->all());
         $category->foods()->save($food);
         $food->savePhotos(['photos' => $request->file('photos'), 'remove_photos' => $request->get('remove_photos'), 'main_photo' => $request->get('main_photo')]);
         return $food;
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(\App\Category $category)
 {
     if ($category->accessable()) {
         return $category->foods;
     }
 }
Exemple #4
0
 public function accessable(\App\Menu $menu, \App\Category $category)
 {
     return $category->id == $this->category_id && $category->accessable($menu);
 }