I have a table "reviews" with a column named "from_user". So basically the user who placed the review. In this column the users's id is stored from the users table. Is it possible to find out the users name in my view?
This is what it looks like now:
@foreach($authUser->reviews as $review)
<p>{{ $review->body }} - {{$review->from_user }}</p>
@endforeach
So this code now obviously displays the id of the user.
This is what my users table looks like:
ID | NAME | USERNAME | ...
This is what my reviews table looks like:
ID | from_user | on_user | body
so the from_user from my reviews table equals the ID of my users table
So my question is is it possible to access my username in my foreach loop in my view?
I am fairly new to laravel so any help is appreciated!
Many thanks in advance
EDIT: User Model
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, Messagable;
protected $table = 'users';
protected $fillable = ['name', 'email', 'password', 'firstname', 'lastname', 'straat', 'postcode', 'plaats', 'provincie', 'role', 'specialisatie'];
protected $hidden = ['password', 'remember_token'];
public function projects()
{
return $this->hasMany('App\Project');
}
public function reviews()
{
return $this->hasMany('App\Review');
}
public function comments()
{
return $this->hasMany('App\Comment');
}
}
EDIT2 my Review model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Review extends Model
{
protected $guarded = [];
protected $table = 'reviews';
public function User()
{
return $this->belongsTo('App\User');
}
}