/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $item = new \App\Item(); $item->title = $request->title; $item->save(); return $item; }
public function run() { DB::table('items')->delete(); $category = App\Category::where('name', '=', 'Food and drink')->first(); App\Item::create(['name' => "Boag's Draught"])->categories()->attach($category->id); App\Item::create(['name' => "Crown Lager"])->categories()->attach($category->id); App\Item::create(['name' => "Toohey's Extra Dry"])->categories()->attach($category->id); }
public function createItem(Request $request, int $listId) { $name = $request->input('name'); $position = $request->input('position', 0); $custom = $request->input('custom', '{}'); if (empty($name)) { return $this->error('Name must be set'); } $item = new \App\Item(); $item->name = $name; $item->list_id = $listId; $item->position = $position; $item->custom = $custom; $result = $item->save(); if (empty($result)) { return $this->error('Failed to save item'); } return $this->read($listId); }
public function postAdd(Request $request) { $this->validate($request, ['name' => 'required|min:2']); $item = new \App\Item(); $item->name = $request->name; $item->amount = $request->amount; $item->user_id = \Auth::id(); $item->store_location = $request->store_location; $item->notes = $request->notes; $item->selected = $request->selected; $item->save(); if ($request->stores) { //Records the stores associated with each item... $stores = $request->stores; //Associaton is done through a pivot table } else { $stores = []; } $item->stores()->sync($stores); \Session::flash('flash_message', 'Your item was added!'); return redirect('/items'); }
/* * * Estimate Create Ajax customer vehicle data call */ Route::get('/ajax-vehicle', function () { $customer_id = Input::get('cust_id'); $vehicles = App\Vehicle::where('customer_id', '=', $customer_id)->get(); return Response::json($vehicles); }); /* * * Estimate Create Ajax item data call */ Route::get('/ajax-item', function () { $item_id = Input::get('item_id'); $item = App\Item::where('id', '=', $item_id)->get(); return Response::json($item); }); /* * * Authentication Route */ Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']); /* * * Resource Routes for All Modules */ Route::resource('items', 'ItemsController'); Route::resource('estimates', 'EstimatesController'); Route::resource('customers', 'CustomersController'); Route::resource('vehicles', 'VehiclesController');
$filter_arr = explode(':', $filter); switch ($filter_arr[0]) { case 'province': $province = DB::table('provinces')->where('id', $filter_arr[1])->first(); $data['cities'] = DB::table('cities')->where('description', 'like', '%' . strtolower($province->name) . '%')->get(); break; case 'branches': $data['branches'] = DB::table('users')->select('branch')->where('branch', '!=', 'null')->where('branch', '!=', '')->groupBy('branch')->orderBy('branch', 'asc')->get(); break; } echo json_encode($data); }); Route::get('/update', function () { switch ($_GET['type']) { case 'tag': $data = App\Item::find($_GET['id']); $data->is_sold = 1; $data->save(); break; } echo json_encode($data); }); Route::get('/', function () { $data['items'] = DB::table('items')->where(['is_sold' => 0])->orderBy('ticket_no', 'desc')->paginate(6); //$data['provinces'] = DB::table('provinces')->lists('name', 'id'); $provinces = DB::table('provinces')->orderBy('name', 'asc')->get(); $data['pawnshops'] = DB::table('pawnshops')->lists('name', 'id'); foreach ($provinces as $value) { $res = DB::table('cities')->where('description', 'like', '%' . strtolower($value->name) . '%')->get(); if ($res) { foreach ($res as $val) {
public function postCreateItem(Request $request) { //Validate the request for the required feilds $this->validate($request, ['item_name' => 'required']); $item = new \App\Item(); $item->item_name = $request->item_name; $item->quantity = $request->item_qty; $item->store_aisle_num = $request->item_store_aisle; $item->store_id = $request->id; $item->save(); \Session::flash('flash_message', 'Item added to store!'); //return redirect('/store'); return redirect('/store/' . $item->store_id . '/items'); }
<?php Route::get('/', function () { return view('welcome'); }); Route::get('/api/artno', function () { $artno = request('q'); $items = App\Item::where('artno', 'LIKE', "%{$artno}%")->get(); return $items->map(function ($item) { return ['id' => $item->artno, 'text' => $item->artno]; }); }); Route::get('/api/artno/{artno}', function ($artno) { return App\Item::where('artno', $artno)->first(['id', 'artno', 'price', 'description']); });
<?php Route::group(['prefix' => 'awesomelist'], function () { get('', function () { return view('home'); }); get('items', function () { return App\Item::all(); }); post('items', function () { $item = App\Item::create(Request::all()); return $item->id; }); put('items/{id}', function ($id) { $item = App\Item::find($id); $item->completed = $item->completed ? false : true; $item->update(); }); delete('items/{id}', function ($id) { $item = App\Item::find($id); $item->delete(); }); });