A component is a group of code like a header or footer. Which are re-useable. Common part of
application.
To Make Component, Open Terminal, and Type php artisan make: component header
In this case, this command creates two file
1st is into app -> view -> Components -> header.php
2nd is into resource -> view - components -> header.balde.php
How To Use Component
Its use is very simple
simply goto header.blade.php
write head section code...
<title>Dipankar Laravel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
After that simply copy and paste <x-header /> into all pages
<head><x-header /></head>
Pass data in the component
Pass header component into all pages
In About Page
<x-header componentName="About Us" />
In Contact page
<x-header componentName="Contact Us" />
After That Goto App>View->Components> header.php
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class header extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $title="";
public function __construct($componentname)
{
$this->title=$componentname;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.header');
}
}
?>
Now Print this
<title>{{$title}} || Laravel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
Create New middleware for the route. php artisan make:middleware MyrouteMiddleware ..
Create a New Middleware php artisan make:middleware NameOfMiddleware This is..
Middleware can verify the user's authentication status and ensure they have the necessary credential..
We have created a view page name as login.blade.php <div class="col-sm-4"><h3>L..
Suppose you have data and you need to check it by clicking or page onload. first, create a controll..
Blade is a templating engine used in Laravel, a popular PHP framework. It provides a simple and expr..
Current Url <div class="container-fluid p-5 bg-primary text-white text-center"><h1..
A component is a group of code like a header or footer. Which are re-useable. Common part ofapplicat..
In Laravel, a controller is a class that handles the logic and acts as an intermediary between themo..
It's Easy to create routes. Already we know That all route files should be kept in the routes ..
The blade is the templating engine used in Laravel, which is a popular PHP framework. It provides at..
Laravel is a popular open-source PHP framework known for its elegant syntax, expressive features, an..
In Laravel, you can set dynamic page titles by utilizing the power of Blade templating and passing d..
To set up a Laravel project with Bootstrap, you can follow these steps: Create a project, I..
How to Install Laravel using Composer First, we need to install Composer. check How to inst..
How to Install Composer on Linux Open terminal php -r "copy('https://getcomposer.o..
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !