dimanche 3 septembre 2017

how to fix Trying to get property of non-object in laravel 5.2

in My Laravel 5.2 application I have tasks table like this

 id      task_name      project_id
    1         aaa               1
    2         hjhkj             2
    3         jhghg             1
    4         jgsdygu           3
    5         gdggfv            2

now I am going to display task names for to relevant each project_id in My index.blade.php file in tasks folder in resource file.

I am using this codes for this

@foreach ($project->tasks as $task)
    <h4><a href="/projects//tasks/"></a></h4>
@endforeach 

now I can seen with tasks name relevant to each project_id. but now I need to click on each task name and display project_id, task id and task name in show.blade.php file witch located in task folder

TaskController.php method for this

 public function getOneProjectTask($projectId, $taskId)
    {
        $task = Task::where('project_id', $projectId)
                      ->where('id', $taskId)
                      ->first();
        return view('tasks.show')->withTask($task)->with('projectId', $projectId);
    }

but I got following error message

Trying to get property of non-object (View: C:\Users\Lilan\Desktop\prome\resources\views\tasks\show.blade.php)

how can fix this problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire