يظهر لي هذا الخطا عند عمل علاقه many to many في لارافيل
وهذه الاكواد اللتى قمت بكتابتها في المشروع
create_projects_doctors.php
في ملف ال migrations
public function up()
{
Schema::create('projects_doctors', function (Blueprint $table) {
$table->id();
$table->foreignId('doctors_id');
$table->foreignId('projects_id');
$table->timestamps();
$table->foreign('doctors_id')
->references('id')
->on('doctors')
->onDelete('cascade');
$table->foreign('projects_id')
->references('id')
->on('projects')
->onDelete('cascade');
// $table->unique(['doctors_id', 'projects_id']);
});
}
//Models doctors//
public function projects()
{
return $this->belongsToMany(project::class, 'projects_doctors');
}
//Models Project//
public function doctors()
{
return $this->belongsToMany(doctors::class, 'projects_doctors');
}
//DoctorsController
public function index()
{
$doctors = doctors::find(1);
$doctors->projects;
dd($doctors);
return view('doctors.index', compact(['doctors']));
}