Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Use of undefined constant..." error in Laravel

I am a Laravel newbie. I want to pass the results of a database query to a view. I get an error message "Use of undefined constant tasks - assumed 'tasks'". What am I doing wrong?

My code is as follows:

class TasksController extends BaseController{
    public function index(){
        $tasks = Task::all();

        //return View::make(tasks.index, ['tasks' => $tasks]);
        return View::make(tasks.index, compact('tasks'));
    }

A snippet from my template page is shown below:

<body>
    <h1>All tasks!</h1>

    @foreach($tasks as $task)
        <li>{{ $task-title }} </li>
    @endforeach
like image 672
user1801060 Avatar asked Oct 15 '25 07:10

user1801060


2 Answers

return View::make('tasks.index')->with(compact('tasks'));

also change:

<li>{{ $task-title }} </li>

to

<li>{{ $task->title }} </li>

should be like this.

like image 167
nCore Avatar answered Oct 17 '25 11:10

nCore


Try this,

 return View::make(tasks.index, $tasks);

instead of

return View::make(tasks.index, compact('tasks'));
like image 37
Krish R Avatar answered Oct 17 '25 12:10

Krish R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!