/** * Run the database seeds. * * @return void */ public function run() { $data = ['Whole Foods', 'Shaws', "Russo's", 'Fish Monger']; foreach ($data as $storeName) { $store = new \App\Store(); $store->name = $storeName; $store->save(); } }
public function postCreateStore(Request $request) { //Validate the request for the required feilds $this->validate($request, ['store_name' => 'required']); //get the store name from request and add to the database $store = new \App\Store(); $store->store_name = $request->store_name; $store->save(); //Adding data to related pivote table $store->users()->attach(\Auth::id()); //show the flash message and redirect page \Session::flash('flash_message', 'New Store "' . $store->store_name . '" is Created in the list!'); return redirect('/store'); }
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]); }
return response()->json(array('status' => 'success', 'data' => $product->toArray())); }); // /stores/:id/ PATCH actualizar info tienda $app->patch('/', function ($id) { $store = App\Store::findByPublicId($id); $input = Request::only('title', 'description'); $validation = Validator::make($input, array('title' => 'required', 'description' => '')); if ($validation->fails()) { return response()->json(array('status' => 'error', 'messages' => $validation->messages())); } $store->update(array('title' => $input['title'], 'description' => $input['description'])); return response()->json(array('status' => 'success', 'data' => $store->toArray())); }); // /stores/:id/ DELETE $app->delete('/', function ($id) { $store = App\Store::findByPublicId($id); $store->delete(); return response()->json(array('status' => 'success')); }); }); $app->group(['prefix' => '/stores/{id}/products/{pid}', 'middleware' => 'valid_product_id'], function ($app) { $app->get('/', function ($id, $pid) { return App\Product::find($pid)->toJson(); }); $app->patch('/', function ($id, $pid) { $product = App\Product::find($pid); $input = Request::only('title', 'description'); $validation = Validator::make($input, array('title' => 'required', 'description' => '')); if ($validation->fails()) { return response()->json(array('status' => 'error', 'messages' => $validation->messages())); }