G
G
Good Samaritan2019-12-24 11:52:16
Laravel
Good Samaritan, 2019-12-24 11:52:16

Why is the variable not visible in the template?

I pass a variable from the controller to the view, but laravel swears
controller

<?php

namespace App\Http\Controllers;

use App\Task;
use Illuminate\Http\Request;

class TaskController extends Controller
{
    public function index() {
        $tasks = Task::paginate(5);
        return view('home',['tasks' => $tasks]);
    }
}

view
@extends('layouts.app')

@section('title', 'Master')




@section('content')
    @foreach ($tasks as $task):
    <div class="card">

        <div class="card-content">
            <span class="card-title activator grey-text text-darken-4">{{$task->title}}<i class="material-icons right">more_vert</i></span>
            <p><a href="#">This is a link</a></p>
        </div>
        <div class="card-reveal">
            <span class="card-title grey-text text-darken-4">{{$task->title}}<i class="material-icons right">close</i></span>
            <p>{{$task->text}}</p>
        </div>
    </div>
    @endforeach
@endsection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Good Samaritan, 2019-12-24
@djamali

The issue was resolved, the route was

Route::get('/', function () {
    return view('home');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question