【发布时间】:2018-09-30 04:00:12
【问题描述】:
我创建了 2 个模型,如下所示:
Employee.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
{
public function grades(){
return $this->belongsTo(Grade::class);
}
}
还有
Grade.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Grade extends Model
{
public function employee(){
return $this->hasMany(Employee::class);
}
}
当我尝试在修补程序中显示代码名称时,如下所示
$a=App\Employee::find(15);<br>
$a->grades->code
它给了我错误:
PHP 通知:试图在第 1 行* 的 Psy Shell 代码中获取非对象的属性“代码”
table employees:
table grades:
【问题讨论】:
-
你能提供正在使用的迁移吗?