I have two tables
1- projects 2- clients
I need to get the names from the client table and the project name from the projects table
my Projects class has
public function projectClient()
{
return $this->hasMany('User');
}
and my User class has
class User extends Eloquent implements UserInterface, RemindableInterface
{
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'client';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
public function project()
{
return $this->belongsTo('Projects', 'id');
}
}
and in my clients controller
$clients = User::with('project')->get();
//dd($clients);
return View::make('admin.manageClients.viewClients', compact('clients'));
now in the view I try this
@foreach($clients as $clt)
{{ $clt->first_name }} //work fine
{{ $clt->pro_title }} //didn't show the project title
@endforeach
how can I show this project title here?
Update
as @Mahfuzul Alam and @WebKenth suggest I did it like this
{{ $clt->project->pro_title }}
but something still wrong there
in my database I got two user and the the project_id
= 1
but in my view
the first user project_id
= 1 and the second project_id
= 2