/** * 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)); }
}); 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)); }));
<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
public function testFindById() { $product = App\Product::find(1); $this->tester->seeRecord('products', ['id' => $product->id, 'code' => $product->code]); }
$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('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());