我有称为“名称”和“团队成员”的模型。我在Laravel(v5.8.4)应用程序中将它们与“模型关系”相关联。这些表还通过数据库中的主键和外键约束进行连接。
错误:
Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Trying to get property of non-object (View: F:\Files\Programming\Web\PHP\wamp\www\Php\Projects\MUC028-CodeLiver128\Laravel\resources\views\administrator\team-members\elements\_grid.blade.php)"
Stacktrace:
#0 Symfony\Component\Debug\Exception\FatalErrorException in F:\Files\Programming\Web\PHP\wamp\www\Php\Projects\MUC028-CodeLiver128\Laravel\storage\framework\views\be1013e7ebf4b2a7b40bda946160daf4cc4fe012.php:0
型号:
class Designations extends Model
{
/**
* Relationships
*/
public function teamMembers()
{
return $this->hasMany(TeamMembers::class);
}
...
}
class TeamMembers extends Model
{
/**
* Relationships
*/
public function designation()
{
return $this->belongsTo(Designations::class);
}
...
}
表格:
Designations:
id
title
...
TeamMembers:
id
designations_id
full_name
...
查看:
@foreach ($data as $key => $value)
{!! $value->designation->title !!}
@endforeach
我尝试使用模型名称(Designations
)代替类Designations::class
,但它不起作用。我总是遇到同样的错误。