Laravel — P9: Displaying Data in Blade Files
We ended our previous article with a quick introduction into Blade. What we really wanted to achieve was introduce what Blade is, understand that there are Blade Directives, and figure out how to load our blade component once a specific route is hit.
In this article, we go deeper. We’re going to look at the following concepts:
- Displaying Data
- Displaying Unescaped Data
Displaying Data
We looked at passing data in the previous article, but we’re going to review it once more. Let’s create a route and pass data to our view.
Route::get('/my-favorite-car', function() {
return view('cars/car', [
'car' => 'Subaru WRX STi',
]);
});
The route /my-favorite-car
will return a view /cars/car
with our favorite car, in this instance the Subaru WRX STi
(RIP STi). We need to create a cars/car.blade.php
file.
You might have noticed that we’re only adding /cars/car
instead of /cars/car.blade.php
. We can do either or, but by…