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.
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.
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.