首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想要求生成laravel特别是infyom模型。

我想要求生成laravel特别是infyom模型。
EN

Stack Overflow用户
提问于 2018-07-18 03:04:12
回答 1查看 166关注 0票数 0

我尝试使用infyom从关系对象数据库的表中使用脚手架,但我不能像POO中那样操作对象,因为生成的模型只包含另一个对象的id!有一种方法可以正确地操作对象吗?

生成的模型如下:

代码语言:javascript
复制
<?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,似乎他们找不到我的对象$personneltypePersonne

EN

回答 1

Stack Overflow用户

发布于 2018-07-18 03:39:26

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

代码语言:javascript
复制
$personnel->SousPersonnel
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51388593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档