However I'll try to introduce you the basics in Laravel:
I assume you have a layouts.blade.php
file in resources\views\layouts
and its corresponding class in app\View\Componets\AppLayout.php
Or similar naming
app.blade.php
file in resources\views\layouts
with the following content: <!DOCTYPE html>
<html lang="en">
<head>
<title>Title of the document</title>
</head>
<body>
<!-- Your Content goes here -->
<div>
{{ $slot }}
</div>
</body>
</html>
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class AppLayout extends Component
{
/**
* Get the view / contents that represents the component.
*
* @return \Illuminate\View\View
*/
public function render()
{
return view('layouts.app');
}
}
This is your base Layout for any pages on your website
routes\web.php
to view the new Layout Route::get('/page1',function (){
return view('page1');
});
page1.blade.php
in resources\views
<x-index-layout>
I'm Page One
</x-index-layout>
php artisan make:component SearchBar
edit resources/views/components/search-bar.blade.php
with something like this:
<label for="search" title="Search">
<input type="search" placeholder="Search...">
</label>
app.blade.php
: <!DOCTYPE html>
<html lang="en">
<head>
<title>Title of the document</title>
</head>
<body>
<!-- Search Bar -->
<x-search-bar/>
<!-- Your Content goes here -->
<div>
{{ $slot }}
</div>
</body>
</html>
This will add your search bar on any page as long as you use the <x-app-layout>
directive on other pages:
run it in the browser with http://{your-url}/page1
you'll see I'm Page One
with the search bar on top
page2.blade.php
in resources\views
with the following content <x-app-layout>
I'm Page Two
</x-app-layout>
Route::get('/page2',function (){
return view('page2');
});
http://{your-url}/page2
you'll see I'm Page Two
with the search bar on top* Be the first to Make Comment