public function storeComment($itemId, Request $request)
 {
     $item = Item::with('comments.user')->findOrFail($itemId);
     $comment = new Comment(['user_id' => $request->userId, 'message' => $request->message]);
     $newComment = $item->comments()->save($comment);
     $result = Comment::with('user')->findOrFail($newComment->id);
     event(new UserPostedAComment($result));
     return $result;
 }
Exemple #2
0
 public function show($id)
 {
     $list = Dramalist::find($id);
     $list->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $items = Item::with(['drama' => function ($query) {
         $query->select('id', 'title', 'type', 'era', 'genre', 'original', 'count', 'state', 'sc', 'poster_url');
     }, 'episode' => function ($query) {
         $query->select('id', 'title', 'alias', 'release_date', 'duration', 'poster_url');
     }])->select('id', 'no', 'drama_id', 'episode_id', 'review', 'created_at', 'updated_at')->where('list_id', $id)->orderBy('no')->paginate(20);
     return view('list.show', ['list' => $list, 'items' => $items]);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $start = microtime(true);
     $collection = Item::with('files')->search($this->argument('term'))->get()->take($this->argument('results'));
     $rows = [];
     foreach ($collection as $item) {
         $path = $item->path;
         $rows[] = ['Item', $item->title, $path];
         foreach ($item->files as $file) {
             $rows[] = ['File', "- {$file->filename}", "{$path}/{$file->filename}"];
         }
     }
     $end = microtime(true);
     $this->table(['type', 'filename', 'path'], $rows);
     $this->line("Took " . round($end - $start, 3) . "s to search");
 }
 public function getEdit($id = null)
 {
     $item = \App\Item::with('stores')->find($id);
     //Get data for the item to be edited
     $amounts_for_dropdown = [0, 25, 50, 75, 100];
     $locations_for_dropdown = ['Aisle', 'Bakery', 'Bulk', 'Dairy', 'Meat', 'Produce', 'Seafood', 'Specialty'];
     $storeModel = new \App\Store();
     //Call the model to get an array of all the possible stores with their id
     $stores_for_checkbox = $storeModel->getStoresForCheckboxes();
     $stores_for_this_item = [];
     foreach ($item->stores as $store) {
         //Create an array of store names for this food item
         $stores_for_this_item[] = $store->name;
     }
     return view('items.edit')->with(['item' => $item, 'amounts_for_dropdown' => $amounts_for_dropdown, 'locations_for_dropdown' => $locations_for_dropdown, 'stores_for_checkbox' => $stores_for_checkbox, 'stores_for_this_item' => $stores_for_this_item]);
 }
 public function demo()
 {
     $new_items = Item::with('itemTags', 'itemInto.item', 'itemFrom.item', 'itemMaps')->get();
     return View::make('item.alldemo')->with('items', $new_items);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $categories = $this->categories;
     try {
         $item = Item::with('images')->findOrFail($id);
     } catch (ModelNotFoundException $ex) {
         Flash::error('No item found' . $ex);
         return redirect()->route('store.items.index');
     }
     return view('store.items.edit', compact('item', 'categories'));
 }