Поэтому я пытаюсь использовать BelongsTo для отображения сведений о клиенте, вот мой текущий код:
мой контроллер:
$assignees = assignee::latest()
->whereNull('timeout')
->paginate(10);
return view('assignees.index',compact('assignees'))
->with('i', (request()->input('page', 1) - 1) * 5);
Назначить таблицу:
$table->string('original_filename')->nullable();
$table->string('custidno')->nullable();
$table->foreign('custidno')->references('custid')->on('customers');
$table->string('cardno')->nullable();
Таблица клиентов:
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('custid')->index()->unique();
Назначить модель:
public function cust()
{
return $this->belongsTo('App\Customer','custid');
}
на мой взгляд: у меня есть следующий цикл for, который отображает «Таблица назначенных лиц», я хочу заменить поле custidnoс именем клиента, взятым из таблицы клиентов.
index.blade.php:
<tr>
<td>{{ $assignee->id }}</td>
<td>{{ $assignee->datacenter }}</td>
<td>{{ $assignee->cust->name}}</td>
<td>{{ $assignee->refnumber }}</td>
Я получаю следующую ошибку:
Попытка получитьсвойство необъекта