Blade in Laravel
What is Blade in Laravel?
How to Create Blade in Laravel?
Why we use a blade?
Of course, it's not practical to return entire HTML documents strings directly from your routes and controllers. Thankfully, views provide a convenient way to place all of our HTML in separate files. Views separate your controller / application logic from your presentation logic and are stored in the resources/views directory. A simple view might look something like this:
E.g:
<!-- View stored in resources/views/greeting.blade.php -->
// Create the new Blade File
<html>
<body>
<h1>Hello</h1>
</body>
</html>
// Calling the Route for Views
// Route::get('aqib', function(){
// return view('aqib');
// });
// Another Method for calling Route
Route:: view('aqib', 'aqib');
O/P
Pass Dynamic data to Laravel Blade | Pass variable in laravel blade:
Since this view is stored at resources/views/greeting.blade.php, we may return it using the global view helper like so:
Example:
// Pass Dynamic data to Laravel Blade
Route::get('aqib', function(){
$name = 'Sheikh Aqib Saeed';
// return view('aqib', ['name' => $name]);
// return view('aqib', compact('name')); // another example passing the key and execute
// return view('aqib', compact('name', 'id', 'Color etc' )); // another example
return view('aqib', )->with('name', $name); // another example
});
O/P

Comments
Post a Comment