Я создаю проект Laravel, в котором администраторы и руководители могут иметь клиентов.
Модель администратора
public function clients()
{
return $this->morphMany('App\Client', 'executable');
}
Client.php
public function executable()
{
return $this->morphTo();
}
Таблица клиентов
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->increments('id');
$table->string('name',100);
$table->morphs('executable');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('clients');
}
При выполнении dd()
$data = App\Admin::find(1)->clients()->get();
Возвращается ноль
Collection {#524 ▼
#items: []
}