Closed dijkr closed 1 year ago
For now it works by also using the category-model within the productController. However, I'm not sure if this is a common / best-practice solution.
Works with this syntax:
$table->unsignedBigInteger('category_id');
$table->foreign('category_id')->references('id')->on('categories');
$table->unsignedBigInteger('subcategory_id');
$table->foreign('subcategory_id')->references('id')->on('subcategories');
$table->unsignedBigInteger('subsubcategory_id');
$table->foreign('subsubcategory_id')->references('id')->on('subsubcategories');
To make it work, the foreign key should exist, before the table can be created. So it might be nessecary to change the sequence of a migration.
Route::get('/{slug}', function ($slug) { return view('producten', [ 'products' => Product::all() ]); });
For example this. I want the product-method have foreign keys to link data from other tables e.g. category. The reason for this problem to happen is a view that is showing product information, but also need the name and banner / image from the category above the products, linked to that specific category.