Routing Through Buttons and Anchor Tags | Laravel 9

Routing Through Buttons and Anchor Tags

Note-  In the entire blog bootstrap 5 is used.

How to use routing through buttons and anchor tags the entire code is given below.


// This is navbar
 <nav class="navbar navbar-expand-sm navbar-dark bg-dark px-5">
      <a class="navbar-brand" href="{{url(&#39;/&#39;)}}">VictoryAlphaWeb</a>
      <button aria-controls="collapsibleNavId" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler d-lg-none" data-bs-target="#collapsibleNavId" data-bs-toggle="collapse" type="button"></button>
      <div class="collapse navbar-collapse" id="collapsibleNavId">
          <ul class="navbar-nav me-auto mt-2 mt-lg-0">
              <li class="nav-item">
                  <a aria-current="page" class="nav-link active" href="{{url(&#39;/&#39;)}}">Home <span class="visually-hidden">(current)</span></a>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="{{url(&#39;/register&#39;)}}">Register</a>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="{{url(&#39;/customer&#39;)}}">Customer</a>
              </li>
          </ul>
      </div>
  </nav>
  
  // this button present in customers data table page
  <a href="{{Route(&#39;customer.create&#39;)}}">
      <button class="btn btn-primary d-inline-block m-2 float-end">Add</button>
  </a>
  

// routes>web.php

Route::get('/', function(){
    return view('index');
});
Route::get('/register', [registrationController::class, 'index']);
Route::post('/register', [registrationController::class, 'register']);

Route::get('/customer/create', [customerController::class, 'index'])-&gt;name('customer.create');
Route::post('/customer', [customerController::class, 'store']);
Route::get('/customer', [customerController::class, 'view']);        

 {{url('/')}} This is first routing method it is used to pass urls as it is->name('customer.crate') is a second method to route pages. In this method we can give the url name. Do not need to use default urls. In case if main url change it will not effect to the url which is passed to other button or anchor tag. 

Comments