Hello I've two tables :
products :
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('title');
...
$table->boolean('slider_mode')->default(false);
});
}
and slider :
public function up()
{
Schema::create('slider', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
...
$table->integer('products_id')->unsigned()->index();
$table->foreign('products_id')->references('id')->on('products')->onDelete('cascade');
});
Problem is when I'm creating products table with slider, product's id is not referencing in products_id
Here is my controller ( store function) :
...
if($x1['slider_mode'] == 1){ # x1 is $request->all();
Slider::create($x1);
}
Product::create($x1);
return redirect('admin/products');
should products_id
is not be completed automatically with product's id when I create both ?
but I'm getting error:
General error: 1364 Field 'products_id' doesn't have a default value