image
what is elias doing in BG

what is elias doing in BG

By Francis in 5 Oct 2022 | 23:28
share
Francis Adegbe

Francis Adegbe

Instructor
Faithful User
Junior Vendor
King Seller
Forums Top User
Posts: 5
Likes: 3
Followers: 2
Member since: 19 Aug 2020

A Different Scenario

In my case, a different scenario came in to the fore as I was unable to log in to the dashboard once I added the above mentioned code. Frontend routes were working perfectly and there was no issue at all until I decided to logout of the dashboard and then log in back.

I tried a lot harder and went through a lot of blogs and forums but none of the solutions worked for me.

A Different Solution Using Middleware

Finally, I decided to try something else and that was to create a middleware that checks the uri request for the presence of trailing slash at the end. If the trailing slash is not present in the uri, then, it appends a trailing slash as I needed.

Here's the piece of code I added in the new middleware I added.

<?php
namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Str;
use Config;

class trailingSlashes
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!preg_match('/.+\/$/', $request->getRequestUri()))
{
$base_url = Config::get('app.url');
return Redirect::to($base_url.$request->getRequestUri().'/');
}
return $next($request);
}
}

Make sure that you have defined the base url of your application in your .env file for this middleware to produce output as expected.

How to create a middleware ?

Creating a middleware is quite easy in laravel. Run the laravel composer and paste the syntax shown below. You can opt for a different name of the middleware though.

5 Oct 2022 | 23:28
1 Likes
 
 

Report

Please describe about the report short and clearly.

(234) 9121762581
[email protected]

GDPR

When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, that blocking some types of cookies may impact your experience of the site and the services we are able to offer.