i'm having an issue with laravel routing, i'm getting 404 HTTP errors when i try to access a specific route.
This is my routing config:
/** Api First Version Routes */
Route::prefix('v1')->group(function(){
// Auth Routes
Route::post('register', 'Api\AuthController#register')->name('register');
Route::post('login', 'Api\AuthController#login')->name('login');
});
My route seems to be accessible on artisan route list command output
but when i try to access through my SPA HTTP Client, it returns a not found http error, image below.
and this error just happens when i try to access the login route.
EDIT***
When i remove the route from the prefix group, it works fine, seems that the problem is just when i'm using routing prefix.
after many hours trying i have solved this problem, i tried to remember what modifications i did in my code before getting errors, so i remembered that i removed the code Passport::routes(); from my App\Providers\AuthServiceProvider.php file.
After adding it back to my AuthServiceProvider.php file all stuff worked again.
Related
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 have some issues with Laravel. I called php artisan route:cache and then the issues began. For example, the Auth routes (login etc.) can be called even if the User is logged in. Then the caching command seems to not clearing the routes. I noticed it because I put my Auth routes in the middleware guests because of the rendering of the Auth routes. After I ran route: clear it worked.
Also, the 404 routing doesn't work since that, because if I call a route that doesn't exist, then the Symfony Framework throws an error:
Symfony\Component\Routing\Exception\ResourceNotFoundException
That's my web.php:
Route::get("/installer","install\InstallController#index");
Route::group(["middleware"=>"guest"],function(){
Auth::routes();
Route::post("login","Auth\Logincontroller#authenticate");
});
Route::group(["middleware" => "auth"], function () {
Route::get("/logout","Auth\LoginController#logOut");
Route::get('/', "dashboard\DashboardController#index");
});
Also, the installer route doesn't work. I will always get redirected to localhost/dashboard (even if I change the route name). My domain for the Laravel is called raptor.debug, so I don't know why it's redirecting to localhost.
Can someone point out what I did wrong or is this a bug?
As Anas Bakro pointed out, the command php artisan route:cache will brick the app, when the folder of the controllers are lowercased.
I've created a project and programmed most the content locally until I've got a server. Now I have a server and I moved the files to the server. After I've got the project run normally, I've got in trouble with the authentification. ( I added the authentification on the server, it wasn't there locally ).
Every time I try to login or to register I only get redirected to the login/register route without any error or something like that. The DB connection works fine, I've tried getting some data from it and that worked.
I looked for the auth routes and tried to return the HTTP header data in the register function but the program doesn't reach this function at all.
I also tried to overwrite the register post Route in Router.php in /vendor/framework/src/Illuminate/Routing/Router.php from:
$this->post('register', 'Auth\RegisterController#register');
to
$this->post('register', 'TestController#test');
Just to look if in the #test function in my TestController will be reached, but nothing. Got redirected again.
However, I haven't changed the auth controller etc. at all besides, the redirect route in the login/register-controller
Here are my routes in my web.php:
Route::group(['middleware' => 'auth', 'web'], function () {
// my routes - the user shall only see them if they are logged in
});
Auth::routes();
If I log a user manually in, everything works fine
I really have no clue what to do anymore, does someone have a clue?
php artisan route:list :
I'm trying to create an api with laravel 5.3 and I've just created a new fresh Laravel 5.3 project and have added the below route to the routes/api.php file.
Route::get('/',function(){
return view('welcome');
});
When I hit this url http://localhost/api/ on my browser I was navigated to the default laravel home page of my application.
Now my question is, shouldn't I get an "Unauthorized access" error when I try to access a route in the api.php file without passing a token? Why is laravel letting me navigate to the api route even when I'm not passing a token?
Note: I have not added laravel passport or any other oAuth libraries to the project yet.
No, Laravel doesn't check those by default when defining routes like that. And thats a good thing because there might be situations where you provide information without the user needing to send a crsf token or authenticate.
What you want is using middleware in your routes. Have a look here: https://laravel.com/docs/5.3/middleware
This will use the specified middleware like 'auth' on certain routes or route groups. i.e.
Route::group(['middleware' => ['auth']], function () {
Route::post('profile', 'ProfileController#create');
....
}
Also see the example on the page with the middlewareGroups 'web'
I have an application using the A2 host provider, and inside the public directory its my laravel folder (www.website.com/app)
And in my server preferences I am redirecting the root "/" to "/app"
The app was OK, but today started to redirect a Route in specific..
Route::get('/postagens/{Alias}/{dataInicio?}', array(
'as' => 'artista.get.posts.all',
'uses' => 'ArtistaController#getPostsMainFeed'
)
);
Inside the generated HTML, it makes:
http://www.website.com/app/artista/posts/twitter/
but when I access this address or send request via jquery, it redirects me to http://www.website.com/artista/posts/twitter, and that gives me a 404 (because There's no laravel app inside root...)
All the other Routes still working...
Any Idea?
Thanks
Editing
I inserted the wrong Route here, but BTW, I "solved" this by making the route without the second parameter, and adding it on the javascript instead using laravel URL::route.
I was having the same problem trying to reach a route on the provided AuthController. It turned out to be middleware set in the constructor that I didn't see.
$this->middleware('guest', ['except' => 'logout']);
Which was 302-ing non-guests to the root page, even for the logout route despite being an exception.