Table of contents

How To Check If Route Name Exists in Laravel 8

Do you need to check if the route name given exists in Laravel 8? Sometimes we need to check the route name if exists. For example, if you have a dynamic menu that will call the available routes in your Laravel 8 application then show it as a menu. But if you don't check the route it will throw an error if one of the routes was deleted/removed.


Using Route:has('route_name') provided by Laravel Framework it will help us to check and determine if the route exists.


Okay here is a simple solution:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

class TestController extends Controller
   public function index() 
      if(Route::has('route_name')) {
        //do something here


Now you can validate if the route name exists in your Laravel application. Thanks, Hope it helps :)