public function store(Request $request) { $this->validate($request, ['product_name' => 'max:255|required|string|unique:products,product_name']); $product = new \App\Product(); $product->product_name = $request->product_name; $product->save(); return response()->json($product); }
public function run() { for ($i = 0; $i < 50; $i++) { $p = new \App\Product(); $p->name = str_random(10); $p->code = str_random(4); $p->price = rand(100000, 999999); $p->save(); } }
public function testSaveDuplicateCode() { $p = new App\Product(); $p->code = "P-006"; try { $p->save(); fail("Harusnya baris ini tidak dijalankan karena ada exception"); } catch (Illuminate\Database\QueryException $e) { // sukses, memang harusnya ada exception } catch (Exception $e) { fail("Jenis exception salah, seharusnya QueryException"); } }
/** * A basic test example. * * @return void */ public function testSamplingCreationWithPost() { $product = App\Product::with('sensors')->get()->random(); $generic_sensors = App\GenericSensor::all(); $generic_sensor_with_random_function = array(); foreach ($generic_sensors as $generic_sensor) { // Humidity, Pressure, Temperature switch ($generic_sensor->alias) { case "Humidity": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomHumidityValue'; break; case "Temperature": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomTemperatureValue'; break; case "Pressure": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomPressureValue'; break; } } $newSamplings = array(); foreach ($product->sensors as $sensor) { $gs_id = $sensor->generic_sensor_id; if (!array_has($generic_sensor_with_random_function, $gs_id)) { continue; } $sensor_random_value = call_user_func(array($this, $generic_sensor_with_random_function[$gs_id])); array_push($newSamplings, array('generic_sensor_id' => $gs_id, 'value' => $sensor_random_value)); } $request_body = array('product_id' => App\Product::all()->random()->getkey(), 'samplings' => $newSamplings); $this->post('api/samplings/create', $request_body)->see('Created ' . count($newSamplings) . ' sampling(s)'); }
public function postAddProduct(Request $request) { $this->validate($request, ['title' => 'required|min:5', 'description' => 'required|min:25', 'file' => 'required|image']); $product = new \App\Product(); $product->title = $request->title; $product->description = $request->description; $file = $request->file('file'); $file_name = $file->getClientOriginalName(); \Storage::disk('local')->put($file_name, \File::get($file)); $product->link_to_image = 'uploads/' . $file_name; $img = Image::make($product->link_to_image)->resize(130, 60); $img->save(); $product->save(); \Session::flash('flash_message', 'Your Product was added!'); return redirect('/addProduct'); }
/** * Run the migrations. * * @return void */ public function up() { $products = App\Product::all(); foreach ($products as $product) { $product->resluggify(); $product->save(); } }
public function postIndex(Request $request, $pid, $mode) { if ($mode == 'Delete') { // use DB facade to delete the row matching $pid \App\Product::destroy($pid); $request->session()->flash('message', 'Product ID ' . $request->input('productID') . ' Deleted'); } else { // validate that the product ID is at least 5 characters $this->validate($request, ['productID' => 'required|min:5', 'productName' => 'required|min:5', 'category' => 'required', 'price' => 'required|numeric|min:3|max:100000', 'discount' => 'required|numeric|min:0|max:30', 'active' => 'required']); // create a model and set the values, then session_save_path if ($mode == 'Edit') { // get the model from the db $products = \App\Product::where('id', '=', $pid)->get(); $product = $products->first(); } else { // instantiate a new model $product = new \App\Product(); } // now set the model attributes $product->product_id = $request->input('productID'); $product->product_name = $request->input('productName'); $product->category_id = $request->input('category'); $product->price = $request->input('price'); $product->max_discount = $request->input('discount'); $product->active = $request->input('active'); if ($mode == 'Edit') { $product->id = $pid; } $product->save(); $request->session()->flash('message', 'Product ID ' . $product->product_id . ' Updated / Added'); } $pcol = $request->session()->get('pcol'); $pord = $request->session()->get('pord'); $pord = $pord == 'A' ? 'D' : 'A'; $request->session()->put('pord', $pord); // need to refresh the products collection after changes $products = \App\Product::orderBy('product_name')->get(); // now put the collection in the session variable $request->session()->put('products', $products); // now direct to the sort route to retain the sort the user had before editing return redirect('products/sort/' . $pcol); }
/** * Test the product creating by sending a post to the product creation route * * @return void */ public function testProductCreationWithPost() { $newProduct = factory(App\Product::class)->make(); $genericSensorIdsCollection = App\GenericSensor::all("id"); $genericSensorIds = array(); foreach ($genericSensorIdsCollection->all() as $genericSensor) { $genericSensorIds[] = $genericSensor->id; } $this->post("api/products/create", array("id" => $newProduct->id, "version" => $newProduct->version, "sensors" => $genericSensorIds)); $this->assertNotNull(App\Product::find($newProduct->id)); }
/** * Paginate my products. */ public function testMyProductsPagination() { $numberOfProducts = 45; // Generate user and products $user = factory(App\User::class)->create(); for ($i = 0; $i < $numberOfProducts; $i++) { $user->products()->save(factory(App\Product::class)->make()); } $paginate = App\Product::where('user_id', $user->id)->orderBy('code', 'asc')->paginate(10); $this->actingAs($user)->get('/my-products/get')->seeJson(['total' => $paginate->total(), 'per_page' => $paginate->perPage()]); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); App\User::truncate(); App\Cart::truncate(); App\Product::truncate(); factory(App\Product::class, 10)->create(); factory(App\User::class, 10)->create()->each(function ($user) { $user->cart()->saveMany(factory(App\Cart::class, 2)->make()); }); Model::reguard(); }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $products = App\Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['uri' => $uri, 'title' => $this->faker->name, 'product_id' => $product->id]); } }
/** * Run the database seeds. * * @return void */ public function run() { factory(App\Order::class, 20)->create()->each(function ($order) { $products = App\Product::all(); foreach ($products as $product) { if (rand(0, 1)) { $qtn = rand(1, 99); $order->total_price += $qtn * $product->price; $order->save(); $order->products()->attach([$order->id => ['quantity' => $qtn, 'product_id' => $product->id]]); } } }); }
public function run() { // Uncomment the below to wipe the table clean before populating DB::table('products_globex')->delete(); $faker = $this->getFaker(); $categories = App\Category::allLeaves()->get(); $category_count = count($categories); for ($i = 0; $i < 200; $i++) { $product = App\Product::create(['title' => $faker->sentence(rand(1, 3)), 'price' => rand(5, 50000), 'description' => $faker->sentence(), 'brand' => $faker->company, 'category_id' => $categories[rand(0, $category_count - 1)]->id]); $product->images()->create(['url' => '/img/noImage.jpg']); $globex = App\Globex::create(['stock' => rand(0, 100), 'price_rule_id' => rand(1, 10)]); $globex->product()->save($product); } }
public function run() { // Uncomment the below to wipe the table clean before populating DB::table('products_ads')->delete(); $faker = $this->getFaker(); $categories = App\Category::allLeaves()->get(); $category_count = count($categories); for ($i = 0; $i < 100; $i++) { $product = App\Product::create(['category_id' => $categories[rand(0, $category_count - 1)]->id, 'title' => $faker->sentence(), 'description' => $faker->paragraph(), 'price' => rand(1, 50000), 'brand' => $faker->company]); $product->images()->create(['url' => '/img/noImage.jpg']); $ad = App\Advertisement::create(['customer_id' => rand(1, 100), 'name' => $faker->name, 'pin' => $faker->postcode, 'address' => $faker->address, 'emirate_id' => rand(1, 7), 'phone' => $faker->phoneNumber]); $ad->product()->save($product); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('users')->delete(); $users = array(); // Loop through each user above and create the record for them in the database foreach ($users as $user) { App\User::create($user); } DB::table('product')->delete(); $products = array(['name' => 'Leki Spin Ngt1 V2 Nordic Walking Pole Pair 100-130 cm Nordic walking', 'brand' => 'Leki', 'description' => '<b>DescriptionFeatures:</b><br><ul><li>Trigger 1 glide zone.</li><li>Match size (S-M-L strap).</li><li>Super lock.</li><li>Diamond tip.</li><li>Power grip.</li><li>Ultrasonic finish.</li></ul><br><b>Specifications:</b><br><ul><li>Lengths: 100 - 130 cm.</li></ul>', 'price' => 68.95, 'imageUrl' => 'https://drms3v40st3o6.cloudfront.net/f/59/593363/asolo-escape-ii-trident-pair.jpg'], ['name' => 'Asolo Escape II Trident Pair', 'brand' => 'Asolo', 'description' => '<b>Specifications:</b><ul><li>Twistlock</li><li>Trident fast release</li><li>2 thin tube segments: 14/16mm sections</li><li>Sections anodized</li><li>Combines Twistlock and Quicklock </li><li>Material: Alu7075</li><li>Size: 90-135cm</li><li>Weight: 220 g</li></ul>', 'price' => 73.95999999999999, 'imageUrl' => 'https://encrypted-tbn3.gstatic.com/shopping?q=tbn:ANd9GcTu0VzMGje4G0pTJ7403WHpqKOz5Z9jCrqgdZaWfoTEoCIPiigT&usqp=CAE']); foreach ($products as $product) { App\Product::create($product); } Model::reguard(); }
$series = [$producto]; } else { $series = App\Product::with('colors')->where('tags', $producto->tags)->get(); } $ids = array($producto->id); foreach ($series as $item) { $ids[] = $item->id; } $relacionados = array(); $prodCat = App\Product::with('colors')->where('category_id', $producto->category_id)->whereNotIn('id', $ids)->take(3)->get(); foreach ($prodCat as $item) { $ids[] = $item->id; $relacionados[] = $item; } if (count($relacionados) < 3) { $prodLast = App\Product::with('colors')->whereNotIn('id', $ids)->take(3 - count($relacionados))->get(); foreach ($prodLast as $item) { $ids[] = $item->id; $relacionados[] = $item; } } return view('pages.product-single', ['producto' => $producto, 'productos_relacionados' => $relacionados, 'series' => $series]); }); Route::get('/team', function () { $team = App\Person::with('gallery')->get(); return view('pages.team', ['team' => $team])->render(); }); Route::get('/garantia', function () { return view('pages.garantia')->render(); }); Route::get('/about', function () {
Route::resource('search', 'SearchController'); Route::get('contactus', 'ContactController@getContactus'); Route::get('confirm-payment', 'ContactController@getConfirmPayment'); Route::post('confirm-payment', 'ContactController@postConfirmPayment'); Route::get('cart', 'CartController@index'); Route::get('profile/{id}', 'Usercontroller@show'); Route::post('profile/{id}', 'Usercontroller@update'); Route::get('checkout', 'CheckoutController@index'); Route::get('checkout/calculate', 'CheckoutController@calculate'); Route::get('checkout/calculate/success', function () { return view('catalog.checkout.success'); }); }); }); Route::get('test', function () { $pros = App\Product::all(); $intersect = $pros; return dd($intersect); }); Route::post('test', function () { }); // Admin Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::group(['middleware' => 'web'], function () { Route::group(['namespace' => 'Auth'], function () { Route::get('login', 'AuthController@getLogin'); Route::post('login', 'AuthController@postLogin'); Route::get('logout', 'AuthController@getLogout'); }); Route::resource('product', 'ProductController'); Route::post('product/{product}/ajax/destroy', 'ProductController@ajaxDestroy');
*/ /* | dependiendo del slug de la url, buscamos el producto en la bd con el mismo slug y |traemos los datos relacionados al producto. |Sometimes you may wish to use your own resolver for route parameters. Simply use the Route::bind method: | | Route::bind('user', function($value, $route) | { | return User::where('name', $value)->first(); | }); */ /*========================================================== | PRODUCTS DEPENDENCY INJECTION ==========================================================*/ Route::bind('product', function ($slug) { return App\Product::where('slug', $slug)->first(); }); /*========================================================== | CATEGORY DEPENDENCY INJECTION ==========================================================*/ Route::bind('category', function ($category) { return App\Category::find($category); }); /*========================================================== | USER DEPENDENCY INJECTION ==========================================================*/ Route::bind('user', function ($user) { return App\User::find($user); }); /*========================================================== | HOME
$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())); } $product->update(array('title' => $input['title'], 'description' => $input['description'])); return response()->json(array('status' => 'success', 'data' => $product->toArray())); }); // /products/:id/ DELETE $app->delete('/', function ($id, $pid) { $product = App\Product::find($pid); $product->delete(); return response()->json(array('status' => 'success')); }); });
}); Route::get('/update', function () { $category = App\Category::find(6); $category->name = "HEAVY METAL"; $category->save(); }); Route::get('/delete', function () { $category = App\Category::find(5); $category->delete(); $categories_list = $category->all(array('name', 'id')); foreach ($categories_list as $categories_list_item) { echo $categories_list_item->id . ' ' . $categories_list_item->name . '<br />'; } }); //API building part of Laravel tutorial Route::get('/api/v1/products/{id?}', array('middleware' => 'auth.basic', function ($id = null) { if ($id == null) { $products = App\Product::all(array('id', 'name', 'price')); } else { $products = App\Product::find($id, array('id', 'name', 'price')); } return Response::json(array('error' => false, 'products' => $products, 'status_code' => 200)); })); Route::get('/api/v1/categories/{id?}', array('middleware' => 'auth.basic', function ($id = null) { if ($id == null) { $categories = App\Category::all(array('id', 'name')); } else { $categories = App\Category::find($id, array('id', 'name')); } return Response::json(array('error' => false, 'user' => $categories, 'status_code' => 200)); }));
<?php $categories = App\Category::where('active', 1)->get(['id', 'name']); ?> <select class="form-control" name="category_id" id="category_id" required> <option value="">-select-</option> @foreach( $categories as $category ) <option value="{{ $category->id }}">{{ $category->name }} </option> @endforeach </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label or="product_id">Product/Area</label> <?php $products = App\Product::where('active', 1)->get(['id', 'name']); ?> <select class="form-control" name="product_id" id="product_id" required> <option value="">-select-</option> @foreach( $products as $product ) <option value="{{ $product->id }}">{{ $product->name }} </option> @endforeach </select> </div> </div> </div> <div class="row"> <div class="col-md-6">
/** * Run the database seeds. * * @return void */ public function run() { App\Product::create(array('proArticleNumber' => '104018585', 'proType' => 'Apple iPhone 5C 8GB', 'proColor' => 'White', 'proAvailable' => 'EOL')); App\Product::create(array('proArticleNumber' => '104018584', 'proType' => 'Apple iPhone 5C 8GB', 'proColor' => 'Blue', 'proAvailable' => 'EOL')); App\Product::create(array('proArticleNumber' => '104025582', 'proType' => 'HTC One M9', 'proColor' => 'Gold', 'proAvailable' => 'EOL')); App\Product::create(array('proArticleNumber' => '104026210', 'proType' => 'Huawei P8', 'proColor' => 'Gold', 'proAvailable' => '2')); }
<div class="clearfix"> <label class="switch"> <input type="checkbox" name="product_active" value="1" {{$checked}}> <span></span> </label> </div> {!!$errors->first('product_active', "<p class='c-red input_error_tips'>:message</p>")!!} </div> </div> </div> <div class="form-group"> <label>商品类型 <span class="c-red">*</span></label> <select class="form-control input_check" name="product_type" id="product_type"> <?php $modelProduct = new \App\Product(); $types = $modelProduct->thisType('all'); ?> @foreach($types as $key => $type) @if($key==$product_type) <option value="{{$key}}" selected>{{$type}}</option> @else <option value="{{$key}}">{{$type}}</option> @endif @endforeach </select> {!!$errors->first('product_type', "<p class='c-red input_error_tips'>:message</p>")!!} </div> <div class="form-group"> <label>商品图片 </label>
* Images */ Route::get('images/search', ['as' => 'images.search', 'uses' => 'ImagesController@search']); Route::bind('images', function ($id) { return App\Image::with('products')->findOrFail($id); }); Route::resource('images', 'ImagesController'); /** * ======================================================== * Products */ Route::get('products/search', ['as' => 'admin.products.search', 'uses' => 'ProductsController@search']); Route::get('products/{slug}/images', ['as' => 'admin.products.edit_images', 'uses' => 'ProductsController@editImages']); Route::post('products/{slug}/images', ['as' => 'admin.products.update_images', 'uses' => 'ProductsController@updateImages']); Route::bind('products', function ($slug) { return App\Product::whereSlug($slug)->with('images')->firstOrFail(); }); Route::resource('products', 'ProductsController'); /** * =========================================================== * Profiles */ Route::post('profiles/image/{id}', ['as' => 'admin.profiles.image', 'uses' => 'ProfilesController@postImage']); Route::bind('profiles', function ($id) { return App\Profile::findOrFail($id); }); Route::resource('profiles', 'ProfilesController', ['except' => 'destroy']); /** * ================================================================================= * Roles */
<tr> <th width="">Product Name</th> <th width="">Quantity</th> <th width="" class="consignment_name_section" @if($stockDetails->entry_type != 'StockIn') style="display:none;" @endif >Consignment Name</th> <th width="" class="to_stock_section" @if($stockDetails->entry_type != 'Transfer') style="display:none;" @endif >To Stock</th> <th width="">Remarks</th> <th width="">Action</th> </tr> </thead> <tbody> </tbody> <?php foreach ($stockDetails2 as $stckDetail) { $productsName2 = App\Product::find($stockDetails->product_id); $category = $productsName2->category->name; $subCategoryName = ''; if ($productsName2->sub_category_id) { $subCategory = App\SubCategory::find($productsName2->sub_category_id); $subCategoryName = '(' . $subCategory->name . ')'; } ?> <tr class="clone_"> <td> <?php echo $stckDetail->product->name . ' (' . $category . ') ' . $subCategoryName; ?> </td> <td> <?php
function kalMenuFromSlug($slug, $with_parent = false) { $subs = App\Product::where('slug', $slug)->first()->getSubs(); return kalMenu($subs); }
Route::get('motors', function () { $data = ['cats' => App\Category::whereDepth(2)->lists('name', 'id'), 'motors' => App\Motor::all()]; return view('temp.motors', $data); }); Route::post('motors', function () { App\Motor::create(['title' => Input::get('title'), 'price' => Input::get('price'), 'stock' => Input::get('stock'), 'brand' => Input::get('brand'), 'description' => Input::get('description'), 'category_id' => Input::get('category_id'), 'chassis_no' => Input::get('chassis_no'), 'model' => Input::get('model'), 'color' => Input::get('color')]); return redirect()->back(); }); Route::get('shitzu', function (AdminPanelRepository $repository) { // return response()->json(array_search('admin/products', array_column($repository->getPages(), 'request', 'title'))); // return response()->json(array_keys(array_column($repository->getPages(), 'request', 'title'), 'admin/products')); // return action('AuthController@registerAdmin'); // return response()->json(App\Product::has('producible')->get()); $motor = App\Motor::find(7); $product = App\Product::find(307); $ad = App\Advertisement::find(101); $ads = App\Advertisement::all(); return response()->json(App\Category::whereDepth(2)->lists('name', 'id')); }); Route::get('files', function () { return response()->json(App\Product::advertisements('asdasd')->get()); }); Route::get('cats', function (\App\Repositories\HomeRepository $repository) { // return response()->json(App\Product::whereIn('id', App\Category::find(1)->childProducts())->get()); // return response()->json(App\Category::find(2)->childProducts()); // $repository->pushCriteria(new \App\Repositories\Criteria\Product\SearchQueryCriteria('asd')); // return response()->json(count($repository->all())); $query = App\Product::whereIn('id', [1, 2, 3])->whereIn('id', [7, 8, 9]); // return response()->json(count($query->get())); return response()->json($repository->getSubCatSet()); });