binggle
1 month ago

want get data or method in relationship .

Posted 1 month ago by binggle

in Post Model

function user()
{
    return $this->belongsTo( \App\User::class);
}

in User Model

function posts()
{
    return $this->hasMany( \App\Post::class);
}


function somedata() 
{
    return  date('i') * 1000  + date('s'); 
}

in Controller

$posts = Post::query()
        ->where('id', 10)
        ->with('user')
        ->get();

but it does not get 'somedata' in user model .

How can I drag this data with posts ?

Please sign in or create an account to participate in this conversation.