I'm using nova to manage a Many to Many relationship between my Pages table and my Featured Content table in the database. I setup a table called featured_content_pages in order to keep track of the Many to Many relationship. It seems to work on first use however it seems that it gets confused at the incramenting of the pages table and trys to map to a page_id that does not exist in the DB yet. Here is a short video of the error in Nova that I receive.
https://drive.google.com/file/d/1jBxO0KZ64XuTxAQVuPgb_5T20YUjDBbi/view?usp=sharing
Here is the migration file of the table I created for mapping the many to many relationship.
Schema::create('featured_content_pages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('page_id');
$table->unsignedBigInteger('featured_content_id');
$table->foreign('page_id')
->references('id')
->on('pages')
->onDelete('cascade');
$table->foreign('featured_content_id')
->references('id')
->on('featured_content')
->onDelete('cascade');
});
Here is what my Pages model looks like
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
use HasFactory;
public function featured_content()
{
return $this->belongsToMany(
FeaturedContent::class,
'featured_content_pages',
'featured_content_id',
'page_id' );
}
}
Here is what my Featured Content model looks like
<?php
namespace App\Models;
use Hamcrest\Thingy;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FeaturedContent extends Model
{
use HasFactory;
protected $table = 'featured_content';
public function pages()
{
return $this->belongsToMany(
Page::class,
'featured_content_pages',
'page_id',
'featured_content_id');
}
public function media_asset()
{
return $this->belongsTo(MediaAsset::class);
}
}