mardi 27 septembre 2016

hasMany and belongsTo relation tables - laravel

My tables :

users :

id fname email

brands:

id title user_id_made

each user has many brands and each brand belongTo an user.

class Brand extends Model
{
    protected $table = 'brands';

    protected $fillable = array('title_fa',
        'title_en','logo','user_id_made');



    public function user()
    {
        return $this->hasOne('App\Models\User');
    }
}

class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'fname' ,'lname' , 'username', 'email', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    public function brand()
    {
        return $this->belongsTo('App\Models\Brand','user_id_made');
    }
}

my code hasn't any output about users .

    $data['brands']         = \DB::table('brands')->find(1);

    var_dump($data['brands']);
    return;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire