An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
April 28, 2021 02:35 pm GMT
Original Link: https://dev.to/jovialcore/how-to-check-for-a-particular-route-then-apply-condition-in-laravel-5c72
How To Check for a particular Route then apply condition in laravel (blade)
I want to use a single nav bar (in layouts/app.blade.php) for all my pages in laravel but I wanted a way I could show a particular search form for only a particular page without duplicating layouts.
Here is how is solved it with named routes:
So I need to check if URL is exactly like, e.g, "page" and then you show something.
My web.php
Route::get('/pages', function () { return view('page');})->name('page');
My layouts/app.blade.php
<nav class="navbar"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="#">Coventions</a> </li> </ul> @if (\Route::current()->getName() == 'page') <form ><input name="s" type="search"></form>@endif <button> Upload </button>
So whats happening above: I simply mean that if the route is same as 'page'
every other thing under the blade @if
(which is the search form )condition will show else, it should just ignore and display the rest.
I hope it helps.
Original Link: https://dev.to/jovialcore/how-to-check-for-a-particular-route-then-apply-condition-in-laravel-5c72
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To