/**
  * @param Request $request
  * @param $input
  * @return static
  */
 public function createMenuItem(Request $request, $input)
 {
     $item = $this->menuItem->create($input);
     if ($request->hasFile('image')) {
         // check if previous photo exists and delete it.
         $item->deletePhoto($item->image);
         // generate a random file name
         $filename = Str::random(10) . time();
         // assinged file input to a variable
         $image = $request['image'];
         $extension = $image->getClientOriginalExtension();
         // open image file
         $photo = Image::make($image->getRealPath());
         $photo->resize(700, null, function ($constraint) {
             $constraint->aspectRatio();
         });
         $photo->crop(700, 525);
         // final file name
         $filename = $filename . '.' . $extension;
         // save file with medium quality
         $photo->save(public_path() . '/uploads/menu_items/' . $filename, 100);
         // get original image file extension
         // store file name in database
         $item->image = $filename;
     }
     $item->save();
     return $item;
 }
Example #2
0
 public function run()
 {
     MenuItem::create(['title' => 'Check-In', 'icon' => 'list', 'view' => 'saferoll/checkins', 'section' => 'saferoll', 'sequence' => 0]);
     MenuItem::create(['title' => 'Rooms', 'icon' => 'building', 'view' => 'saferoll/rooms', 'section' => 'admin', 'sequence' => 0]);
     MenuItem::create(['title' => 'Children', 'icon' => 'child', 'view' => 'saferoll/children', 'section' => 'admin', 'sequence' => 1]);
     MenuItem::create(['title' => 'Daycare Settings', 'icon' => 'bed', 'view' => 'saferoll/settings', 'section' => 'admin', 'sequence' => 2]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(MenuItemRequest $request)
 {
     $menuitem = MenuItem::create($request->all());
     flash()->message('Successfully added new menu items: ' . $menuitem->name, 'success');
     return redirect()->route('admin.menuitems.index');
 }