I'm relatively new to laravel, but was wondering if there is a way using artisan to have it return the route that would be run if supplied a given request URI.
I know I can get a list or routes using:
php artisan route:list
And I can filter routes with --name, --method, --path, etc., but I'm looking for a method to supply a URI path, and have artisan return the route that would match...
Something like
php artisan route:list --requestURI=blog/this-is-my-slug/
with the desired result showing the route URI that laravel would have been directed it to... such as blog/{slug}
Is there anyway to get the route from a request URI using artisan?
Currently there is no predefined command exists for this. But you can do it by creating your own artisan commands. Check official Laravel documentation for custom commands in here.
Related
In the new Laravel 9 project, after installing the UI, I have a problem with the php artisan route:cache command. Message appears:
Unable to prepare route [password/reset] for serialization. Another
route has already been assigned name [password.request]. Checking
route:list, no duplicate route.
Everything is fine on the local server, but some routes are not working on the hosting.
Are the names of those route not the same?
By the name I mean the "name" method as follow bellow:
Route::get('/user', [UserController::class, 'index'])->name('thisMustBeAnUniqueName);
I'm trying to develope a program with Laravel, I have a problem with a Route, it shows me that is not define but it's already defined, also, I'm using Ajax.
This is the Error
This is my Ajax with URL and Route
And I tried to put the Route in that part of the code, but when I put there I get other problem.
I have tried this
Thank so much for your help.
After adding new route you need to clear cache. So run this commands:
php artisan cache:clear
php artisan route:cache
And check again
You have same controller method two time define and you did changed only route name? so it can return error. remove first route then it will work fine.
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory');
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('orders.schedules.store');
please remove Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory'); route.
I am currently working on an API only laravel application. In the controllers folder, there is an API folder that holds all controllers. The ForgotPasswordController is in the API folder as well.
When I run the command php artisan route:list I get the error below
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\Auth\ForgotPasswordController] does not exist.
There is actually no ForgotPasswordController in the Auth folder. How do I handle this issue?
You have to make sure you are doing php artisan route:cache priority.
If the problem still persists, can you disable the auth provider and try?
For the sake of time considering that the project is live and I need to churn out a couple of features, I have moved both ForgotPassword and ResetPassword controllers back into the Auth folder. Ran a test to make sure nothing has been broken (everything works fine) and now I am able to list out the routes.
If you have Auth::routes() or Route::auth() in your routes file that would be generating routes to the ForgotPasswordController.
You would need to not be calling that or you would need to pass the proper option to it to have it not register those routes:
Auth::routes(['reset' => false]);
Depending on the version you are using this may not work. If that is the case you will have to not use this method at all and register the routes you want/need yourself.
I Blog in Laravel v5.6
when translate new route it doesn't work for me
but old route like login and register and landing pages it working as well when i going in new route it's not
Switch Lang page
Route::get('locale/{locale}', function ($locale) {
Session::put('locale', $locale);
return redirect()->back();
// this link will add session of language when they click to change langauge
})->name('locale');
Route::get('/{username}', 'ProfileAccountController#index')->name('profile')->middleware('admin.user');
when i going to this route it's not working and navbar and footer it's back to key, remove all code in this page and test the lang it's not work too.
I use all of this command and nothing
php artisan config:cache
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
Thank you.
My suggestions:
Use middle-wear for changing languages and use https://github.com/spatie/laravel-translatable like this for more comfortable usage.
Also check this Change language in Laravel 5 might help you.
Had similar issues with Route closures. Try moving you're session setters/getters to a Controller and not within a Route closure.
https://laravel.com/docs/5.7/session#using-the-session
This will probably solve your issues.
I created a new controller with resources using the PHP artisan command:
php artisan make:controller AdminCategoriesController --resource
The file gets added to the controller folder but when I visit my route list with I see no route about it:
php artisan route:list
Here my routes list:
How can I add the categories to my routing list?
This error is showing because you did not give instance of Resource Controller in web.php file.
Route::resource('route','AdminCategoriesController ');
When you did this , route list will show.
I failed to add the route resource in my routes.php
Route::resource('/admin/categories', 'AdminCategoriesController');
Everything works now.
If you are using api then use this syntax to generate controller
php artisan make:controller API/PhotoController --api