我尝试访问关系数组,但出现错误。
这是我的广告系列模型:
class Campagne extends Model
{
protected $table = 'Campagne';
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'Id';
public $incrementing = false;
public function Annonceur()
{
return $this->belongsTo('App\Annonceur', 'Annonceur');
}
}
在我的数据库中,我有很好的外键,在我的debugbar中,我有这个对象:
0 => Campagne {#574 ▼
#table: "Campagne"
#attributes: array:12 [▼
"Id" => 7
"Nom" => "ORANGE"
"DateDebut" => null
"DateFin" => null
"Annonceur" => 25
"Service" => 25
"Description" => null
"Active" => null
"Visible" => 1
"CommerceMaj" => null
"created_at" => "2019-04-27 15:00:43"
"updated_at" => "2019-04-27 15:00:43"
]
#relations: array:1 [▼
"Annonceur" => Annonceur {#610 ▼
#table: "Annonceur"
#primaryKey: "Id"
#fillable: array:12 [▶]
#connection: "mysql"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:17 [▶]
#original: array:17 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
]
}
我必须访问“ Annonceur”关系属性,但是尝试时出现错误:
$campagne->Annonceur->Name 举个例子。