I updated laravel 5.6 project to laravel 6 in order to use the laravel-permission spatie package. It uses the default auth provided by Laravel. I can't access the auth routes and it appears as I am logged in while still seeing Login | Register on the navbar.
This is my route list
| GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController#showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController#login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController#showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController#register | web,guest |
| | GET|HEAD | {any} | | App\Http\Controllers\LexaController#index | web |
Your error suggests that Laravel can't find your auth views. Is your register and login view located at: resources/views/auth? You might have to move them there if they aren't.
Related
Hello fellow developpers, I need your wisdom
I am creating a laravel API with an oauth2 authentication process (passport authorization code flow) used by a Vuejs decoupled client and I can't authenticate through the usual process (401 Unauthenticated).
If I try with the laravel project blade views it works as expected, but as soon as I try to do a separated project for the frontend, I end up with a 401 Unauthenticated error when getting to the oauth/authorize route and I can't get any information about what's wrong so I can't go further in my project.
For now, I don't even use inputs, I just send the request I need :
(of course i send the parameters that suits the ones I have in the oauth client database)
public function authorizeTpp(Request $request)
{
$query = http_build_query([
'client_id' => '3',
'redirect_uri' => 'http://api.dirapp.test/auth/callback',
'response_type' => 'code',
'scope' => '*',
]);
return redirect('http://api.dirapp.test/oauth/authorize?'.$query);
}
Here is my AuthServiceProvider :
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
Here is my Kernel :
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
CreateFreshApiToken::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
And here are my routes :
web.php :
Auth::routes();
Route::get('auth/callback', 'Auth\LoginController#authCallback');
api.php :
Route::get('authorize', 'Auth\LoginController#authorizeTpp');
and the routes :
+--------+----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+
| | GET|HEAD | api/authorize | | App\Http\Controllers\Auth\LoginController#authorizeTpp | api,guest |
| | POST | api/create-client | | App\Http\Controllers\HomeController#createOauthClient | api |
| | POST | api/create-user | | App\Http\Controllers\HomeController#createUser | api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | auth/callback | | App\Http\Controllers\Auth\LoginController#authCallback | web,guest |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web |
| | POST | login | | App\Http\Controllers\Auth\LoginController#login | web,guest |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController#showLoginForm | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | GET|HEAD | oauth/authorize | passport.authorizations.authorize | Laravel\Passport\Http\Controllers\AuthorizationController#authorize | web,auth |
| | POST | oauth/authorize | passport.authorizations.approve | Laravel\Passport\Http\Controllers\ApproveAuthorizationController#approve | web,auth |
| | DELETE | oauth/authorize | passport.authorizations.deny | Laravel\Passport\Http\Controllers\DenyAuthorizationController#deny | web,auth |
| | POST | oauth/clients | passport.clients.store | Laravel\Passport\Http\Controllers\ClientController#store | web,auth |
| | GET|HEAD | oauth/clients | passport.clients.index | Laravel\Passport\Http\Controllers\ClientController#forUser | web,auth |
| | PUT | oauth/clients/{client_id} | passport.clients.update | Laravel\Passport\Http\Controllers\ClientController#update | web,auth |
| | DELETE | oauth/clients/{client_id} | passport.clients.destroy | Laravel\Passport\Http\Controllers\ClientController#destroy | web,auth |
| | GET|HEAD | oauth/personal-access-tokens | passport.personal.tokens.index | Laravel\Passport\Http\Controllers\PersonalAccessTokenController#forUser | web,auth |
| | POST | oauth/personal-access-tokens | passport.personal.tokens.store | Laravel\Passport\Http\Controllers\PersonalAccessTokenController#store | web,auth |
| | DELETE | oauth/personal-access-tokens/{token_id} | passport.personal.tokens.destroy | Laravel\Passport\Http\Controllers\PersonalAccessTokenController#destroy | web,auth |
| | GET|HEAD | oauth/scopes | passport.scopes.index | Laravel\Passport\Http\Controllers\ScopeController#all | web,auth |
| | POST | oauth/token | passport.token | Laravel\Passport\Http\Controllers\AccessTokenController#issueToken | throttle |
| | POST | oauth/token/refresh | passport.token.refresh | Laravel\Passport\Http\Controllers\TransientTokenController#refresh | web,auth |
| | GET|HEAD | oauth/tokens | passport.tokens.index | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController#forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | passport.tokens.destroy | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController#destroy | web,auth |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController#showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController#register | web,guest |
+--------+----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+
When using internal laravel blade views, I can go through the whole process,
going to oauth/authorize route, getting the 'authorize' view where I can validate or cancel the client registration, then going to oauth/token through the callback route, and then getting my user authenticated and redirected to the homepage.
As soon as I try to get the same results with an external/decoupled frontend project (Vuejs), the oauth/authorize route gives me a 401 Unauthenticated error while using same credentials.
I don't know if it is related or not, but when using the decoupled client I don't have a session anymore and I loose the 'intended_url' usually used by the auth process to do the proper redirection and it brings me to the homepage instead.
To fix this, my API send to my client the proper encoded intended_url so I can send it back to the login function when needed and go to the real intended_url after the auth process.
I don't know what i'm doing wrong and I need help, I think I might have misunderstood the way passport works but there is not much informations about the authorization code flow process through a decoupled client that I can get.
I spent a few days on this without any success so if you have any information or can give me any help it would be awesome.
Thanks.
I've built a website using Laravel that I'm happy with, however, due to not planning ahead I have built the admin/management panel, and now that I have to go through and do the user front end I'm wondering how I should have though to handle this.
Currently I have a web.php file containing lines like this:
# WEDDING HANDLING
Route::get('/admin/weddings', 'WeddingController#index');
Route::get('/admin/wedding/create', 'WeddingController#create');
Route::get('/admin/wedding/{wedding}', 'WeddingController#show');
Route::get('/admin/wedding/{wedding}/edit', 'WeddingController#edit');
Route::post('/admin/wedding/create', 'WeddingController#store');
Route::put('/admin/wedding/{wedding}/edit', 'WeddingController#update');
Route::delete('/admin/wedding/{wedding}/destroy', 'WeddingController#destroy');
# MENU HANDLING
Route::get('/admin/wedding/{wedding}/menus', 'MenuController#index');
Route::get('/admin/wedding/{wedding}/menu/create', 'MenuController#create');
Route::get('/admin/wedding/{wedding}/menu/{menu}', 'MenuController#show');
Route::get('/admin/wedding/{wedding}/menu/{menu}/edit', 'MenuController#edit');
Route::post('/admin/wedding/{wedding}/menu/create', 'MenuController#store');
Route::put('/admin/wedding/{wedding}/menu/{menu}/edit', 'MenuController#update');
Route::delete('/admin/wedding/{wedding}/menu/{menu}/delete', 'MenuController#destroy');
...continues
So from that you can probably see that I have multiple controllers that handle this for the admin, however, if a user logs in, they should be able to view the menus against the wedding, which I can stack with #auth tags, and seperate it out like that, however I'm afraid I'm going to end up with a web.php that looks like the following:
# WEDDING HANDLING
Route::get('/admin/weddings', 'WeddingController#index');
Route::get('/weddings', 'WeddingController#index');
...continues
Hopefully from my demo you can see what I'm asking.
tl;dr: How would you go about seperating User/Management areas without duplicating a ton of code.
You would need to create different controllers just to handle the front-end, like: FrontEndMenuController#yourFunction
you could also separate your admin routes into a group with the prefix 'admin' instead of repeating it on all the routes:
Route::prefix('admin')->group(function () {
Route::get('/wedding/{wedding}/menus', 'MenuController#index');
Route::get('/wedding/{wedding}/menu/create', 'MenuController#create');
Route::get('/wedding/{wedding}/menu/{menu}', 'MenuController#show');
Route::get('/wedding/{wedding}/menu/{menu}/edit', 'MenuController#edit');
});
And then have your front-end routes like that:
Route::get('/wedding/{wedding}/menu', 'FrontEndMenuController#index');
As you are almost adhering to the CRUD/REST convention, an addition to Adriano Marra's answer would be to also use resource controllers.
From Laravel documentation about resource controllers:
Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code.
Introducing Resource Controllers
In your use case your resource are the weddings, so you could rewrite your web.php routes as:
Route::prefix('admin')->group(function () {
Route::resource('weddings', 'WeddingsController');
});
These lines would register such routes:
+--------+-----------+-------------------------------+------------------+-------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------+------------------+-------------------------------------------------+------------+
| | GET|HEAD | admin/weddings | weddings.index | App\Http\Controllers\WeddingsController#index | web |
| | POST | admin/weddings | weddings.store | App\Http\Controllers\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/create | weddings.create | App\Http\Controllers\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding} | weddings.show | App\Http\Controllers\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding} | weddings.update | App\Http\Controllers\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding} | weddings.destroy | App\Http\Controllers\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/edit | weddings.edit | App\Http\Controllers\WeddingsController#edit | web |
+--------+-----------+-------------------------------+------------------+-------------------------------------------------+------------+
NOTE: There's a small difference as the Route::resource(...) method uses the plural resource name you provided to it (weddings) for all the seven routes, and the singular form for the parameter name (wedding).
You could then register the menus resource in the same way:
Route::prefix('admin')->group(function () {
Route::resource('weddings', 'WeddingsController');
// Personally, I would make 'menus' a top level resource but I will
// stick to your routing example for the rest of the answer.
Route::resource('weddings/{wedding}/menus', 'WeddingMenusController');
});
Named Group Resource Routes
Furthermore you could also register the frontend wedding controller as a resource
Route::prefix('admin')->group(function () {
Route::resource('weddings', 'WeddingsController');
Route::resource('weddings/{wedding}/menus', 'WeddingMenusController');
});
// This will map only two methods for this resource.
Route::resource('weddings', 'FrontendController')->only(['index', 'show']);
The routes registered by your application would be:
+--------+-----------+--------------------------------------------+------------------+-------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+--------------------------------------------+------------------+-------------------------------------------------+------------+
| | GET|HEAD | admin/weddings | weddings.index | App\Http\Controllers\WeddingsController#index | web |
| | POST | admin/weddings | weddings.store | App\Http\Controllers\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/create | weddings.create | App\Http\Controllers\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding} | weddings.show | App\Http\Controllers\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding} | weddings.update | App\Http\Controllers\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding} | weddings.destroy | App\Http\Controllers\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/edit | weddings.edit | App\Http\Controllers\WeddingsController#edit | web |
| | GET|HEAD | admin/weddings/{wedding}/menus | menus.index | App\Http\Controllers\WeddingsController#index | web |
| | POST | admin/weddings/{wedding}/menus | menus.store | App\Http\Controllers\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/create | menus.create | App\Http\Controllers\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu} | menus.show | App\Http\Controllers\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding}/menus/{menu} | menus.update | App\Http\Controllers\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding}/menus/{menu} | menus.destroy | App\Http\Controllers\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu}/edit | menus.edit | App\Http\Controllers\WeddingsController#edit | web |
| | GET|HEAD | weddings | weddings.index | App\Http\Controllers\FrontendController#index | web |
| | GET|HEAD | weddings/{wedding} | weddings.show | App\Http\Controllers\FrontendController#show | web |
+--------+-----------+--------------------------------------------+------------------+-------------------------------------------------+------------+
If you look close at the above table, you will notice that the name column has some duplicate values. This would create conflict when you need to reference these particular routes by name anywhere in your application.
So you could solve this by prefixing the admin group's named routes with a custom prefix:
Route::prefix('admin')->name('admin.')->group(function () {
Route::resource('weddings', 'WeddingsController');
Route::resource('weddings/{wedding}/menus', 'WeddingMenusController');
});
// This will map only two methods for this resource.
Route::resource('weddings', 'FrontendController')->only(['index', 'show']);
This would solve any route conflict, as the administation routes has been correctly prefixed with admin. name:
+--------+-----------+--------------------------------------------+------------------------+-------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+--------------------------------------------+------------------------+-------------------------------------------------+------------+
| | GET|HEAD | admin/weddings | admin.weddings.index | App\Http\Controllers\WeddingsController#index | web |
| | POST | admin/weddings | admin.weddings.store | App\Http\Controllers\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/create | admin.weddings.create | App\Http\Controllers\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding} | admin.weddings.show | App\Http\Controllers\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding} | admin.weddings.update | App\Http\Controllers\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding} | admin.weddings.destroy | App\Http\Controllers\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/edit | admin.weddings.edit | App\Http\Controllers\WeddingsController#edit | web |
| | GET|HEAD | admin/weddings/{wedding}/menus | admin.menus.index | App\Http\Controllers\WeddingsController#index | web |
| | POST | admin/weddings/{wedding}/menus | admin.menus.store | App\Http\Controllers\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/create | admin.menus.create | App\Http\Controllers\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu} | admin.menus.show | App\Http\Controllers\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding}/menus/{menu} | admin.menus.update | App\Http\Controllers\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding}/menus/{menu} | admin.menus.destroy | App\Http\Controllers\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu}/edit | admin.menus.edit | App\Http\Controllers\WeddingsController#edit | web |
| | GET|HEAD | weddings | weddings.index | App\Http\Controllers\FrontendController#index | web |
| | GET|HEAD | weddings/{wedding} | weddings.show | App\Http\Controllers\FrontendController#show | web |
+--------+-----------+--------------------------------------------+------------------------+-------------------------------------------------+------------+
Namespacing Groups
Finally, you could go further with optimizations with introduction of namespaces (useful if you start to have more and more controllers).
You can create a folder in you app/Http/Controllers, for example Administration, where you store all of your administrative controllers.
In the web.php file, you just have to tell Laravel that the admin prefixed route group should look for controllers in the newly created folder:
Route::prefix('admin')->namespace('Administration')->name('admin.')->group(function () {
Route::resource('weddings', 'WeddingsController');
Route::resource('weddings/{wedding}/menus', 'WeddingMenusController');
});
// This will map only two methods for this resource.
Route::resource('weddings', 'FrontendController')->only(['index', 'show']);
This would lead to register these routes:
+--------+-----------+--------------------------------------------+------------------------+----------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+--------------------------------------------+------------------------+----------------------------------------------------------------+------------+
| | GET|HEAD | admin/weddings | admin.weddings.index | App\Http\Controllers\Administration\WeddingsController#index | web |
| | POST | admin/weddings | admin.weddings.store | App\Http\Controllers\Administration\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/create | admin.weddings.create | App\Http\Controllers\Administration\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding} | admin.weddings.show | App\Http\Controllers\Administration\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding} | admin.weddings.update | App\Http\Controllers\Administration\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding} | admin.weddings.destroy | App\Http\Controllers\Administration\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/edit | admin.weddings.edit | App\Http\Controllers\Administration\WeddingsController#edit | web |
| | GET|HEAD | admin/weddings/{wedding}/menus | admin.menus.index | App\Http\Controllers\Administration\WeddingsController#index | web |
| | POST | admin/weddings/{wedding}/menus | admin.menus.store | App\Http\Controllers\Administration\WeddingsController#store | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/create | admin.menus.create | App\Http\Controllers\Administration\WeddingsController#create | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu} | admin.menus.show | App\Http\Controllers\Administration\WeddingsController#show | web |
| | PUT|PATCH | admin/weddings/{wedding}/menus/{menu} | admin.menus.update | App\Http\Controllers\Administration\WeddingsController#update | web |
| | DELETE | admin/weddings/{wedding}/menus/{menu} | admin.menus.destroy | App\Http\Controllers\Administration\WeddingsController#destroy | web |
| | GET|HEAD | admin/weddings/{wedding}/menus/{menu}/edit | admin.menus.edit | App\Http\Controllers\Administration\WeddingsController#edit | web |
| | GET|HEAD | weddings | weddings.index | App\Http\Controllers\FrontendController#index | web |
| | GET|HEAD | weddings/{wedding} | weddings.show | App\Http\Controllers\FrontendController#show | web |
+--------+-----------+--------------------------------------------+------------------------+----------------------------------------------------------------+------------+
You can create a new FrontEndController, and route any front end pages to that controller.
Route::get('/admin/weddings', 'WeddingController#index');
Route::get('/weddings', 'FrontEndControllerController#showWeddings');
Then you can use middlewear to diferentiate and refactor any repeated code into the Wedding model and just call that.
This is what i do when i need to separate admin and front end routes
Route::group([
'prefix' => 'admin',
'namespace' => 'Admin', // assumed
// 'as' => 'admin.'
// 'middleware' => 'admin.'
], function () {
Route::get('weddings', 'WeddingController#index');
Route::group([
'prefix' => 'wedding',
], function () {
// Wedding Management
Route::get('{wedding}/show', 'WeddingController#show'); // Updated with /show in url otherwise it will overlap create
Route::get('{wedding}/edit', 'WeddingController#edit');
Route::put('{wedding}/edit', 'WeddingController#update');
Route::delete('{wedding}/destroy', 'WeddingController#destroy');
Route::get('create', 'WeddingController#create');
Route::post('create', 'WeddingController#store');
// Here you differentiate WeddingController and MenuController
// Route::group([
// 'middleware' => 'only_applied_to_this_group',
// ], function () {
// Menu Management
Route::get('{wedding}/menus', 'MenuController#index');
Route::get('{wedding}/menu/create', 'MenuController#create');
Route::get('{wedding}/menu/{menu}', 'MenuController#show');
Route::get('{wedding}/menu/{menu}/edit', 'MenuController#edit');
Route::post('{wedding}/menu/create', 'MenuController#store');
Route::put('{wedding}/menu/{menu}/edit', 'MenuController#update');
Route::delete('{wedding}/menu/{menu}/delete', 'MenuController#destroy')
// });
});
});
Route::group([
'namespace' => 'Front',
'as' => 'front.'
], function () {
// Front-end Management
});
I tried to make it more simplified for better routes understanding, i hope this works.
this is the first time that I try to migrate a Laravel application from my local environment to my remote server.
So basically I have uploaded the entire content of my local Laravel 5.4 application into this folder of my remote server:
/var/www/html/HotelRegistration
Then I am trying to opening this URL into the browser (my remote server):
http://89.36.211.48/HotelRegistration/public/
and how you can see the standard Laravel homepage appear (it is expected, I yet have to replace this page with a custom one).
The problem is that in my web.xml file I have declared these routes:
Route::get('/', function () {
return view('welcome');
});
Route::get('contact', function() {
return View::make('contact');
});
Route::post('contact', 'EnquiryController#index');
Route::resource('/registration', 'RegistrationController');
The first one is the one related to the standard Laravel page that works fine, the last one is:
Route::resource('/registration', 'RegistrationController');
and it should handle HTTP GET request toward the /registration by the RegistrationController class, this controller class contains this index() method:
/**
* Metodo che mostra la pagina di registrazione di un nuovo utente albergatore.
* #return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(){
Log::info('index() START');
return view('/registration/index');
}
that opening this URL:
http://89.36.211.48/HotelRegistration/public/registration
should show a registration page. But, as you can see opening it I obtain a Not Found error message.
Into the /var/www/html/HotelRegistration/storage/logs/laravel.log file there is nothing, I expected the output of the log putted at the beginning of the previous method controller, so it seems that it doesn't not enter in this method.
The strange thing is that opening the same URL on my localhost system (http://localhost/HotelRegistration/public/registration) it works fine.
I am thinking that maybe it could be a routes problem (maybe some route is missing), if I perform this statment on my local environment:
php artisan route:list
I obtain:
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | activate | | App\Http\Controllers\RegistrationController#activate | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | contact | | Closure | web |
| | POST | contact | | App\Http\Controllers\EnquiryController#index | web |
| | GET|HEAD | errors | errors | Closure | web |
| | POST | registration | registration.store | App\Http\Controllers\RegistrationController#store | web |
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
| | GET|HEAD | registration/create | registration.create | App\Http\Controllers\RegistrationController#create | web |
| | DELETE | registration/{registration} | registration.destroy | App\Http\Controllers\RegistrationController#destroy | web |
| | PUT|PATCH | registration/{registration} | registration.update | App\Http\Controllers\RegistrationController#update | web |
| | GET|HEAD | registration/{registration} | registration.show | App\Http\Controllers\RegistrationController#show | web |
| | GET|HEAD | registration/{registration}/edit | registration.edit | App\Http\Controllers\RegistrationController#edit | web |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
that contains this route:
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
that should be the route related to the previous index() method of my controller.
But I can found it also performing the same statment on my remote environment:
root#Betrivius-VPS:/var/www/html/HotelRegistration# php artisan route:list
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | activate | | App\Http\Controllers\RegistrationController#activate | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | contact | | Closure | web |
| | POST | contact | | App\Http\Controllers\EnquiryController#index | web |
| | GET|HEAD | errors | errors | Closure | web |
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
| | POST | registration | registration.store | App\Http\Controllers\RegistrationController#store | web |
| | GET|HEAD | registration/create | registration.create | App\Http\Controllers\RegistrationController#create | web |
| | GET|HEAD | registration/{registration} | registration.show | App\Http\Controllers\RegistrationController#show | web |
| | PUT|PATCH | registration/{registration} | registration.update | App\Http\Controllers\RegistrationController#update | web |
| | DELETE | registration/{registration} | registration.destroy | App\Http\Controllers\RegistrationController#destroy | web |
| | GET|HEAD | registration/{registration}/edit | registration.edit | App\Http\Controllers\RegistrationController#edit | web |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
So what could be the problem? Why on my remote environment this URL (http://89.36.211.48/HotelRegistration/public/registration) seems not to be hanbdled as done in the local one?
What could be the problem? What am I missing? How can I try to fix it?
You need to first change the permissions and give the requires permission and run this command
composer install
or
composer update
Thank you
Should a redirect with flash data persist the flash data if the auth middleware is involved?
A few housekeeping things to note that will answer some possible followup questions:
I am calling the web middleware.
I'm using the file sessions driver.
I can retrieve values stored in the session with the exception of flashed data.
I have tried reflashing the flashed data by adding the following line to the Authenticate middleware:
$request->session()->reflash();
As such, Authenticate.php now appears as follows:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
$request->session()->reflash();
return $next($request);
}
This issue is also affecting the auth boilerplate generated by make:auth, resulting in the $errors failing to display on error.
UPDATE (3/29 # 08:54 EST)
I uncovered what I believe to have been the root cause, as you will see below. Each route was calling 'web' middleware twice. As such, two requests were actually taking place which was removing the flash message(s) before the user had a chance to see them. Original route:list is below.
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | groups | | App\Http\Controllers\GroupsController#index | web,web,auth |
| | GET|HEAD | groups/set-default/{id} | | App\Http\Controllers\GroupsController#setDefaultGroup | web,web,auth |
| | GET|HEAD | home | | App\Http\Controllers\HomeController#index | web,web,auth |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController#showLoginForm | web,web,guest |
| | POST | login | | App\Http\Controllers\Auth\AuthController#login | web,web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController#logout | web,web |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController#sendResetLinkEmail | web,web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController#reset | web,web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController#showResetForm | web,web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController#showRegistrationForm | web,web,guest |
| | POST | register | | App\Http\Controllers\Auth\AuthController#register | web,web,guest |
| | GET|HEAD | visitees | | App\Http\Controllers\VisiteesController#index | web,web,auth |
| | GET|HEAD | visitees/check-in/{id} | | App\Http\Controllers\VisiteesController#checkIn | web,web,auth |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
My routes now appear as follows after removing the routes from the 'web' middleware:
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | groups | | App\Http\Controllers\GroupsController#index | web,auth |
| | GET|HEAD | groups/set-default/{id} | | App\Http\Controllers\GroupsController#setDefaultGroup | web,auth |
| | GET|HEAD | home | | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController#showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\AuthController#login | web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController#logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController#sendResetLinkEmail | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController#showResetForm | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController#showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\AuthController#register | web,guest |
| | GET|HEAD | visitees | | App\Http\Controllers\VisiteesController#index | web,auth |
| | GET|HEAD | visitees/check-in/{id} | | App\Http\Controllers\VisiteesController#checkIn | web,auth |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
Upon moving the routes out of the 'web' middleware group, the flash message display correctly. But, now I have a new issue!
The flash messages are not being removed from the session after the initial request. They persist each subsequent request until they are manually flushed or forgotten.
I'm not sure at this point if I should open up a second question that specifically addresses the persisting of the flash data. Please advise if so.
please run a composer update to update laravel/framework to v5.2.27, then issue php artisan make:auth to regenerate auth routes
I am working on a CMS of my own, but I'm experiencing some difficulties with slugs, so, here is my problem:
I'm trying to use slugs on the root of my URLs like so:
http://domain.com/some-slug-to-some-article
At this point I have the following entries in my app/routes.php
Route::get('/', 'ArticleController#index');
Route::get('/{slug?}', 'ArticleController#show');
The problem appears when I am try to enter to the "login" area of the site, which for default is in /home (I'm using the scaffold for user authentication in Laravel 5.1)
When I enter the URL for domain.com/home it stills calling it as a slug.
Here's my route:list
+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+------------+
| | GET|HEAD | / | | App\Http\Controllers\ArticleController#index | |
| | POST | auth/login | | App\Http\Controllers\Auth\AuthController#postLogin | guest |
| | GET|HEAD | auth/login | | App\Http\Controllers\Auth\AuthController#getLogin | guest |
| | POST | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#postLogin | guest |
| | GET|HEAD | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getLogin | guest |
| | GET|HEAD | auth/logout | | App\Http\Controllers\Auth\AuthController#getLogout | |
| | GET|HEAD | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getLogout | |
| | POST | auth/register | | App\Http\Controllers\Auth\AuthController#postRegister | guest |
| | GET|HEAD | auth/register | | App\Http\Controllers\Auth\AuthController#getRegister | guest |
| | GET|HEAD | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getRegister | guest |
| | POST | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#postRegister | guest |
| | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | | App\Http\Controllers\Auth\AuthController#missingMethod | guest |
| | GET|HEAD | home | | \Bestmomo\Scafold\Http\Controllers\HomeController#index | auth |
| | POST | home/article | home.article.store | App\Http\Controllers\ArticleController#store | auth |
| | GET|HEAD | home/article | home.article.index | App\Http\Controllers\ArticleController#index | auth |
| | GET|HEAD | home/article/create | home.article.create | App\Http\Controllers\ArticleController#create | auth |
| | GET|HEAD | home/article/{article} | home.article.show | App\Http\Controllers\ArticleController#show | auth |
| | PUT | home/article/{article} | home.article.update | App\Http\Controllers\ArticleController#update | auth |
| | DELETE | home/article/{article} | home.article.destroy | App\Http\Controllers\ArticleController#destroy | auth |
| | PATCH | home/article/{article} | | App\Http\Controllers\ArticleController#update | auth |
| | GET|HEAD | home/article/{article}/edit | home.article.edit | App\Http\Controllers\ArticleController#edit | auth |
| | GET|HEAD | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#getEmail | guest |
| | POST | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#postEmail | guest |
| | POST | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#postReset | guest |
| | GET|HEAD | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#getReset | guest |
| | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing} | | App\Http\Controllers\Auth\PasswordController#missingMethod | guest |
| | GET|HEAD | {slug?} | | App\Http\Controllers\ArticleController#show | |
+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+-------------
So in short words, I want to have the slugs at the root of the URL but also, I want to "exclude" some routes to keep it to the system itself.
Thanks for your help.
For further requirements, I've solved the problem adding this rule at the beginning of the routes.php
Route::get('home', 'HomeController#index');
Also, #StuartWagner said that clearing the routes.php should be empty the routes this was not true at all, once cleared the routes.php this is what the php artisan route:list show me:
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
| | POST | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#postLogin | guest |
| | GET|HEAD | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getLogin | guest |
| | GET|HEAD | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getLogout | |
| | GET|HEAD | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#getRegister | guest |
| | POST | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController#postRegister | guest |
| | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | | App\Http\Controllers\Auth\AuthController#missingMethod | guest |
| | GET|HEAD | home | | \Bestmomo\Scafold\Http\Controllers\HomeController#index | auth |
| | POST | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#postEmail | guest |
| | GET|HEAD | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#getEmail | guest |
| | POST | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#postReset | guest |
| | GET|HEAD | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController#getReset | guest |
| | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing} | | App\Http\Controllers\Auth\PasswordController#missingMethod | guest |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
In some where is declared this route for "home".
Hope this helps anyone.
Cheers.