Laravel - Route to subdomain with session data - laravel

I'm using laravel for my project, i have two subdomains where both point to the same app, app.project.com,user.project.com
When the user logs in on app.project.com i want to route him to user.project.com but the issue is that sessions aren't transfered so the user is router to user.project.com but faces the login page again
Any solution ?

Found a solution
in config/session.php make sure this is found
'domain' => env('SESSION_DOMAIN', null),
and in .env
SESSION_DOMAIN=.project.com

Related

How can I add a subdomain to Admin Panel Laravel Backpack(backpackforlaravel)?

How can I add a subdomain to Admin Panel Laravel Backpack?
I want to add a subdomain to my Laravel Backpack admin panel, I need point 'admin.example.com' subdomain to Laravel Backpack admin Panel.
Laravel Backpack provides route prefix for Admin Panel.
I want to use the same project source code for the site, admin and API.
admin.example.com -> Admin
api.example.com -> API
www.example.com -> Site
You can get Laravel Backpack to run under a subdomain, for example admin.app.local, instead of the prefix (for example app.local/admin) as follows:
In the .env file, you can define the admin subdomain, something useful if you work in different environments where it changes:
ADMIN_SUBDOMAIN = admin.app.local
Optionally you can also define in config/app.php, whether or not the admin will use subdomain, adding:
'use_admin_subdomain' => true,
Then in the config/backpack/base.php file, you will want to stop using the admin route prefix, since you will use admin in the subdomain, so you must define:
'route_prefix' => '',
Then in routes/backpack/custom.php, you will be able to include all routes under a new group, which will determine if the admin backpack runs under a subdomain (defined in app.use_admin_subdomain) and the subdomain (defined in env('ADMIN_SUBDOMAIN'), and all the original routes and groups will go within:
Route::group (
config('app.use_admin_subdomain') ? ['domain' => env('ADMIN_SUBDOMAIN')]: []
, function () {
... original backpack routes
});
Optionally in the same backpack routes file, you can remove the prefix of the original routes, commenting:
'prefix' => config ('backpack.base.route_prefix', 'admin'),
Although being empty in config/backpack/base.php has no effect yet without commenting.
You can follow the same procedure to define your API routes under the api.app.local subdomain, in that case in routes/api.php file.

how to remove register and login form routes and leave everything else?

I am using Laravel 5.8 and I need to remove the routes that lead to login and registeration form but I want leave everything as it is (verify email, reset password) would you tell me how to do this kindly?
If you have ever run this command to generate the authentication files
php artisan make:auth
and you no longer need the files for the reason that you are doing login and registration using ajax, then you may have to remove the views associated with the files and remove some routes in the associated controllers that you do not need.
For instance, if you do not need the login and registration forms and the associated routes, you can follow the outlined steps below to remove them.
If you are in doubt of the routes that you need, first run this artisan command:
PHP artisan route:list
to see the details of the available routes and note the ones you need.
Thereafter, delete the auth route definition in routes/web.php
Auth:routes();
and declare the routes you need explicitly. In your case you should need post routes for registration/login and also the email verification routes:
Route::post('login', 'Auth\AuthController#login');
Route::post('logout', 'Auth\AuthController#logout');
Route::post('register', 'Auth\AuthController#login');
Route::get('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');
Route::get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
Route::post('email/verify/{id}', 'Auth\VerificationController#verfy')->name('verification.verify');
Next, remove the views contained in the following default locations
resources/views/auth/login.blade.php
and
resources/views/auth/register.blade.php
These are the views for the respective forms.
Then remove showLoginForm() and showRegistrationForm() from
app/Http/Controllers/Auth/LoginContoller.php
and
app/Http/Controllers/Auth/RegisterController.php`
respectively.
I am using Laravel 8 and this is how you can achieve it
Auth::routes([
'register' => false, // Register Routes...
'login' => false, // Login Routes...
]);

How to register a route in laravel for SPA admin panel

I am writing a SPA administrative panel site for example (http: // localhost) there you go there a form for entering a login and password, routes laravel handled it and the routes themselves were vue-route
Route::get('/{any}', 'AdminPanelController#index')->where('any', '.*');
Everything works fine, but then I decided to move it to a folder (http: // localhost / admin) and for some reason it does not work
Route::get('/admin/{any}', 'AdminPanelController#index')->where('any', '.*');
If you moved Your whole laravel application, than you'll probably have to adjust your server settings (DocumentRoot). If you moved only your AdminPanelController than I would check if the namespaces are correct. What kind of error are you getting?

How to pass the sessions and sessions auth of the App laravel to package And vice versa?

Do you know how to pass the sessions and session auth of the App laravel to package, and vice versa? It does not work for me, I do not know what I'm missing. Thank you.
According to the image you have provided it looks like they have registered separate route file instead of default one.
Try wrapping the routes inside the web middleware like
Route::group([middleware' => 'web'], function() {
//Your routes here
});
Without the web middleware your session won't work.

Laravel 5 - weird sessions

in my application, after few requests, Laravel sessions randomly expired.
On my site, i had invalid links to images, i repaired them and everything works fine now.
What could be the problem? How could repairing links helped Laravel sessions from not being randomly deleted?
All your routes are inside middleware 'web' ? If you redirect to a route outside 'web' you loose sessions. Check that and return please.

Resources