/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $input = Input::all();
     $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
     $category = new Category();
     $category->restaurant_id = $restaurant->id;
     $category->category = $input['nombreCategoria'];
     $category->save();
     return redirect('admin/categories');
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $menuOption = "analitics";
     $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
     $dishes = Dish::where('restaurant_id', $restaurant->id)->get();
     $categories = Category::where('restaurant_id', $restaurant->id)->get();
     $dishesIds = Dish::where('restaurant_id', $restaurant->id)->lists('id');
     $categoriesIds = Category::where('restaurant_id', $restaurant->id)->lists('id');
     $dishesAnalytics = Analitic::where('related_table', 'dishes')->whereIn('related_id', $dishesIds)->get();
     $firstDay = Analitic::where('related_table', 'dishes')->whereIn('related_id', $dishesIds)->min('date');
     $categoriesAnalytics = Analitic::where('related_table', 'categories')->whereIn('related_id', $categoriesIds)->get();
     return view('backend.pages.analitics')->with(compact('dishesAnalytics', 'menuOption'));
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('backend.partials.leftPanel', function ($view) {
         $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
         $view->with(compact('restaurant'));
     });
     view()->composer('backend.partials.headerPanel', function ($view) {
         $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
         $view->with(compact('restaurant'));
     });
     view()->composer('*', function ($view) {
         $arr = explode('.', $view->getName());
         view()->share('VIEW', $arr[count($arr) - 1]);
     });
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
     $input = Input::all();
     if (filter_var($input['emailRestaurante'], FILTER_VALIDATE_EMAIL)) {
         if (preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}\$/", $input['telefonoRestaurante'])) {
             $restaurant->name = $input['nombreRestaurante'];
             $restaurant->email = $input['emailRestaurante'];
             $restaurant->telephone = $input['telefonoRestaurante'];
             $restaurant->address = $input['direccionRestaurante'];
             $restaurant->save();
             return redirect('admin/config');
         }
     } else {
         return redirect('admin.config.index');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
     $input = Input::all();
     $dish = Dish::find($id);
     $dish->restaurant_id = $restaurant->id;
     $dish->name = $input['nombrePlato'];
     $dish->description = $input['descripcionPlato'];
     $dish->cost = $input['precioPlato'];
     if (isset($input['is_active'])) {
         $dish->is_active = true;
     } else {
         $dish->is_active = false;
     }
     $dish->save();
     $dish->categories()->detach();
     if (isset($input['categoriaPlato'])) {
         for ($i = 0; $i < sizeof($input['categoriaPlato']); $i++) {
             $dish->categories()->attach($input['categoriaPlato'][$i]);
         }
     }
     return redirect('admin/dishes');
 }