简体   繁体   中英

i want to ask for laravel espcially infyom models generated

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

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

$personnel->SousPersonnel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM