How can I list routes specifically the api routes in my view?
For example These:
...api/user
...api/Information
The artisan command for example does list them like this:
php artisan route:list
The route:list command can be used to show a list of all the registered routes for the application. This command will display the domain, method, URI, name, action and middleware for the routes it includes in the generated table.
Accessing The Current RouteThe Route::current() method will return the route handling the current HTTP request, allowing you to inspect the full Illuminate\Routing\Route instance: $route = Route::current(); $name = $route->getName();
The Default Route Files All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider .
Views may also be returned using the View facade: use Illuminate\Support\Facades\View; return View::make('greeting', ['name' => 'James']); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.
In your controller you can get the list of routes using Artisan
facade. I assume all your api
routes have api
string in its path.:
public function showRoutes($request) {
$routes = Artisan::call('route:list', ['--path' => 'api']);
return view('your_view', compact('routes'));
}
Edit :
You can also use Route
facades getRoutes
method.
$routes = [];
foreach (\Route::getRoutes()->getIterator() as $route){
if (strpos($route->uri, 'api') !== false){
$routes[] = $route->uri;
}
}
return view('your_view', compact('routes'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With