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); }
<label class="col-md-2 control-label">Active</label> <select class="form-control" name="active" id="active"> <option value="1">Active</option> <option value="0">Inactive</option> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="category_id">Category</label> <?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']); ?>
|-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/home', 'HomeController@index'); Route::get('/', 'WelcomeController@index'); Route::get('/item', 'WelcomeController@item'); /** Category - Products */ Route::model('categories', 'Category'); Route::model('products', 'Products'); Route::bind('products', function ($value) { return App\Products::where("slug", $value)->first(); }); Route::bind('categories', function ($value) { return App\Category::where("slug", $value)->first(); }); Route::resource('categories', 'CategoryController'); Route::resource('categories.products', 'ProductController'); Route::get('/products', 'ProductController@index', ["as" => 'products.index']); /** Order */ Route::model('order', 'App\\Order'); Route::resource('order', 'OrderController'); /** Cart */ Route::controller('cart', 'CartController'); /** Profile */ Route::controller('account', 'AccountController'); /** Auth */ Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
function categoryIdToName($id) { $Category = App\Category::where('id', $id)->get()->first(); return $Category['kategori']; }