JerVi
JerVi

Reputation: 131

how to create a blade template in laravel 5?

I have a challenge: I can't get a blade file working as expected following the Laravel guide for such a purpose.

I know a Laravel blade file must end with the .blade.php.

Every time I create a blade file, I get an error as the file cannot be found, but that is not the case with a pure PHP file.

Below is my route definition to return my blade test file, testblade.blade.php:

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

When returning a pure PHP file in my route file, testphpalone.php, I define my route as follow:

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

I'm concerned because I cannot use blade helper functions such as @yield() and @extends() directly in the pure PHP file, but a blade one (which I can't get working).

What am I doing wrong and how can I make it work?

Upvotes: 0

Views: 3779

Answers (4)

Ibrahim Max Alyousfi
Ibrahim Max Alyousfi

Reputation: 126

I had this problem and it was the server, I was using the XAMPP. How I found out is that I ran my project on an online server and it worked perfectly.

The Solution is just to run your project using the command:

php artisan serve

then browse your project using:

localhost:8000

Upvotes: 0

Manvir Singh
Manvir Singh

Reputation: 431

In config\view.php check the path of the views

'paths' => [
    realpath(base_path('resources/views')),
]   

Upvotes: 1

Gayan
Gayan

Reputation: 3704

you only can use blade syntax in a blade file. As a best practice always name view files using .blade.php syntax.

find more on blade syntax here

Upvotes: 1

nyedidikeke
nyedidikeke

Reputation: 7658

Taking into consideration your route definition;

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

your blade template file should be testblade.blade.php and located in your resources/views directory as in: resources/views/testblade.blade.php for a proper implementation.

Upvotes: 1

Related Questions