lundi 11 mars 2019

Cannot access hasMany models

Model Joindraw.php

class Joindraw extends Model
{
    protected $table = 'joindraw';
    public function user(){
        return $this->belongsTo('App\Models\User', 'user_id');
}

Model User.php

class User extends Authenticatable
{
    public function joindraw() {
        return $this->hasMany('App\Models\Joindraw');
}

IndexController.php

public function details(Request $request, $id, $fortune_code=null)
{
    $joindraw_participants = Joindraw::where('product_id', $id)->get();

View.blade.php

@forelse($joindraw_participants as $record)
    

How can i access the child model from joindraw? and vice versa? I'm getting error of getting property from non-object.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire