L
L
lemonlimelike2018-10-25 23:17:02
Laravel
lemonlimelike, 2018-10-25 23:17:02

How to display data on blade laravel?

Hello! very hard blunt. So, I have the main template index.blade.php Here is its code:

@include('components.header')
<div class="grid">
    <div class="grid__width-1">
        @yield('sidebar')
    </div>
    <div class="grid__width-2">
        @yield('content')
    </div>
</div>

As you can see, I include the site header via include. Then I make the main content: sidebar and content.
Here is my only route: Route::get('/', '[email protected]');
Controller code:
use App\Category;

class HomeController extends Controller
{
    public function cat()
    {
        $cat = Category::all();
        $data = ['cat'=>$cat];
        return view('main.index', $data);
    }
}

And here is the sidebar.blade.php file code:
@extends('main.index')
@section('sidebar')
<aside>
    @foreach($cat as $item)
        <a href="{{ route('category',$item->name ) }}" class="aside__link"></a>
    @endforeach
</aside>
@endsection

Why is my code not showing up? What is the problem?
Explain how this blade works in simple terms please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Agelios, 2018-10-26
@lemonlimelike

You have the index.blade.php template, but you connect main.index
In the [email protected] root, but in fact you don’t have an index, but cat
And if in general, you need to ask the question not how blade works, but how laravel works in general.
Watch some video tutorials on laracast or youtube

D
Dmitry, 2018-10-26
@Astatroth

RTFM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question