Lilan
Lilan

Reputation: 163

how to print project_name using project_id in Laravel 5.2

in My laravel app I have tasks table as below,

id      task_name      project_id
    1         aaa               1
    2         hjhkj             2
    3         jhghg             1

project table as below,

id     name   
1       abc
2       xyz

task model relationship with project model is

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

I am printing some data using task table in show.blade.php

{{$tasks->project_id}}

{{$tasks->task_name}}

actually now I need print project name here also, how can do this?

Upvotes: 0

Views: 51

Answers (1)

noufalcep
noufalcep

Reputation: 3536

Try

{{ $tasks->project->name }}

Upvotes: 1

Related Questions