I have a table "articles" in this table a column name "user_id", I have another table "users" where store username, profile_pic etc... I want to fetch username on home page where I already fetched articles title.
Article Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function category()
{
return $this->belongsTo('App\Category');
}
public function tags()
{
return $this->belongsToMany('App\Tag');
}
}
View Page(Home Page)
Here I want to Display username
User Model
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire