Nightcrawler
Nightcrawler

Reputation: 1051

How to render view usin Laravel blade?

enter image description hereI am trying to create simple application using Laraver(8) Blade, I am a complete beginner in Blade, I want to rednder extended view in my template, but it doesn't works, also it doesn't throwing any errors, The page is refreshed my view not showing, what i am doing wrong?

main layout:

<!DOCTYPE html>
    <html>
    <head>
    @include('layout.header')
    @stack('css')
    </head>
    <body id="body">
    <div class="blackscreen"></div>
    <div class="blackscreen2"></div>
    @yield('content')
    <script src="{{url('js/developer.js')}}"></script>
    @stack('js')
    </body>
    </html> 

template:

@extends('layout.main')
@section('content')
    <h1>hello</h1>
@endsection

route:

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

    Route::get('/test2', function () {
        return view('layout/main');
    });

this is my file structure

Upvotes: 0

Views: 1400

Answers (1)

The Manh Nguyen
The Manh Nguyen

Reputation: 465

if you save your template into resources/views/template.blade.php, you should call view method like this:

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

if you save your template into other folder inside resources/views, like resources/views/test/template.blade.php, you should call view method like this:

Route::get('/', function () {
    return view('test.template');
});

Upvotes: 1

Related Questions