我尝试使用infyom
从关系对象数据库表中使用脚手架,但是我无法像在POO中那样操作对象,因为生成的模型仅包含另一个对象的ID!有办法正确地操纵物体吗?
生成的模型如下:
<?php
namespace App\Models;
use Eloquent as Model;
/**
* Class Facture
* @package App\Models
* @version July 17, 2018, 6:08 pm UTC
*
* @property \Illuminate\Database\Eloquent\Collection Consomme
* @property \Illuminate\Database\Eloquent\Collection contient
* @property \Illuminate\Database\Eloquent\Collection EstFactureBst
* @property \App\Models\EstFacture estFacture
* @property string num_facture
* @property date date_facture
* @property string etat_facture
* @property integer num_releve
*/
class personnel extends Model
{
public $table = 'personnel';
public $timestamps = false;
public $sousPersonnel;
protected $primaryKey = 'id_pers';
public $fillable = [
'id_pers',
'lib_pers'
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'lib_pers' => 'string'
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
];
public function SousPersonnel(){
return $this->hasMany(\App\Models\TypePersonne::class);
}
}
我的班级人员和TypePErsonne
之间存在某种关系,但是当我想像$personnel->typePersonne
那样写并使dd我为空时,我使用Eloquent ORM
似乎他们不能为我的对象typePersonne
找到$personnel
答案 0 :(得分:0)
您已经在名为SousPersonnel()
的方法中定义了关联,因此要阅读它,您应该使用SousPersonnel
属性,如下所示:
$personnel->SousPersonnel