dongwen7730 2018-07-17 19:04
浏览 115

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

I try to use scaffold from table of relational-object database using infyom but i can't manipulate object like in POO because the models generated contains only the id of the other object! there is a way to manipulate object correctly?

model generated is like:

<?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);
    }
}

there is a relation between my class personnel and TypePErsonne but when I want to write like $personnel->typePersonne and make dd I have it null I use Eloquent ORM it seems like they can't find typePersonne for my object $personnel

  • 写回答

1条回答 默认 最新

  • duanfei8399 2018-07-17 19:39
    关注

    You have defined relation within the method named SousPersonnel() so to read it you should use SousPersonnel attribute like this:

    $personnel->SousPersonnel
    
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000