我想询问生成的laravel特别是infyom模型

时间:2018-07-17 19:04:12

标签: php laravel-5

我尝试使用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

1 个答案:

答案 0 :(得分:0)

您已经在名为SousPersonnel()的方法中定义了关联,因此要阅读它,您应该使用SousPersonnel属性,如下所示:

$personnel->SousPersonnel