I'm starting a new project with Laravel 5.7. I've made standard laravel Auth with artisan. It registered a new route in routes/web.php which is
Route::get('/home', 'HomeController#index')->name('home');
The problem is when i rename '/home' to '/admin' it doesn't work. It returns 'The requested resource /admin was not found on this server.' error.
I can replace '/home' with anything except '/admin'. Anything else works without a problem.
What is wrong with '/admin' and why can't i use '/admin' as a route?
You can't use this '/admin' route because your project may have 'admin' folder (but not listing file due server config).
Simply rename your admin folder or use '/admin/home' instead.
Related
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'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.
I am using Ubuntu 16.04 and installed Laravel 5.3 on desktop/Laravel/test directory. I have created a test.blade.php file in resources/view directory. I have also created routes.php in app/Http directory and added following code:
Route::get('/', function(){
return view('test');
});
When I enter command in terminal: php artisan serve and go to http://localhost:8000 url in browser, it shows default page of laravel after installation. Why it is not showing view I have created? I have also tried writing following code in routes.php:
Route::get('/', function(){
echo "Test";
})
But still it doesn't work. Is there anything I am missing?
Reference
By default, fresh Laravel 5.3 applications contain two HTTP route
files in a new top-level routes directory. The web and api route files
provide more explicit guidance in how to split the routes for your web
interface and your API.
The routes.php is moved to different folder in Laravel 5.3. Update routes/web.php file.
From the Laravel Documentation 5.3
The routes directory contains all of the route definitions for your application. By default, three route files are included with Laravel: web.php, api.php, and console.php.
The routes.php was there in previous version. But in laravel 5.3 the routes.php is moved to routes/web.php as Saumini Navaratnam said.
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.