我尝试使用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);
}
}我的类personnel和TypePErsonne之间有关系,但是当我想像$personnel->typePersonne一样编写并使dd为空时,我使用Eloquent ORM,似乎他们找不到我的对象$personnel的typePersonne
发布于 2018-07-18 03:39:26
您已经在名为SousPersonnel()的方法中定义了关系,因此要读取它,您应该使用SousPersonnel属性,如下所示:
$personnel->SousPersonnelhttps://stackoverflow.com/questions/51388593
复制相似问题