/** * 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)'); }
/** * Run the migrations. * * @return void */ public function up() { $products = App\Product::all(); foreach ($products as $product) { $product->resluggify(); $product->save(); } }
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]]); } } }); }
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');
}); 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)); }));