jeudi 29 septembre 2016

get two users in a post in laravel

i have a users table with many users.example 1:mike, 2:nina, 3:john. and i have a posts table with user_id, which is the original creator of the post. and then i editors who can edit the post later on. any user can lock or open. thus if a post is locked only he can edit it while it is locked. so i have a field named locked_user_id in the posts table. I can have the laravel relationships as follows.

in User model:

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

in Post model:

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

i can retrieve the author easily by

$posts->user->name

but how do i assume locked_user_id is a username id, and get its value, such as the name of the user who locked the post. can be the author at first and editor later on.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dyzNIP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire