Laravel4 Session handling issue? - laravel-4

I want to use Laravel Database Session. I have changed
'driver' => 'database',
in session.php.
When I try to access application i.e during landing page or before login
I am getting this error
null value in column "data" violates not-null constraint DETAIL
But if this error comes after login, then it is fine. Because that is when session is created. I did not understand why it is coming during application load.
Please let me know what is the issue or Please let me know the tutorial link for session handling in Laravel4
Thanks all

The "data" value you reference doesn't exist in the implementation of the Laravel session handler. The fields are id, payload and last_activity.
If you're trying to use Laravel's session handler via database, you're going to need to run the Laravel migrations.
Go to your command line and run artisan. php artisan session:table will automatically create the Laravel session migrations.
Then run composer dump-autoload or composer.phar dump-autoload (depending on your implementation).
Next, php artisan migrate and your Laravel session table will be created! You'll now be able to use laravel's built-in session handler.
Documentation here: http://laravel.com/docs/session#database-sessions

Related

Laravel session ID changes on each request

Every time I reload the page, I get a new value out of session()->getId().
Some have suggested adding the laravel_session to the unencrypted cookie exception, but this does not fix it and is not a viable option anyway.
The issue persists no matter which session storage method I use. File, redis, etc all have the same problem.
This is happening on a fresh install of Laravel 7.
Contents of .env:
SESSION_DRIVER=redis
SESSION_LIFETIME=1440
SESSION_DOMAIN=example.test
What's causing this?
That means:
Session driver is not starting up properly
Client you're using to connect to laravel app server does not accept cookies
Cookies are set up for wrong domain and/or path.
For case 1 make sure StartSession middleware exists in app/Kernel.php at $middlewareGroups -> web
For case 3 check this answer. In case your app relies on a single domain/path, I recommend you to remove SESSION_DOMAIN.
Finally, manually remove all sessions from your session driver, then run php artisan config:cache and try again.

Laravel 5.2 How to authenticate with a real mysql database

I'm new with laravel, I read the documentation of laravel, but I don't know how I make an authentication with a real mysql database.
I mean, I see that there is a php migration command, but it makes a table in php and not in my database right ?
Actually, I have a mysql database with a user table with login and password.
I'm lost with this framework, because I never used a php framework.
Thanks !!
Edit :
Excuse me, I misspoke and my problem has evolved, how did you to authenticate with a user table already exists in the database by using the Authentication service?
in .env or config>database.php you can set your database and related database connections configurations
after that create migrations and run them it will create database tables in your database as per your .env or config>database.php database configurations.
I think you might need to read again Laravel documentations.
Try the following.
Make sure you have a database create in your MySql.
Check again your .env for: database_host, database_name, database_user, database_password - make sure you have the right
Try bellow code on your route.php
Route::get('/', function () {
if(DB::connection()->getDatabaseName())
{
echo "Yes! successfully connected to the DB: " . DB::connection()->getDatabaseName();
}
});
If above is successful your migration should work.

Unable to store session in Database in laravel 5.2

I recently upgraded my application from laravel 5.1 to 5.2 version. Also I am trying to store session in Database which is currently stored in file.
I have changed .env file to include SESSION_DRIVER=database. Also I have changed session.config file to include 'driver' => env('SESSION_DRIVER', 'database') and generated required session table.
But when I tried to login to the application I am getting TokenMismatchException in VerifyCsrfToken.php line 67: If I change SESSION_DRIVER=file then application is working as expected.
But this was not the case in Laravel 5.1 version.
What is changed in Laravel 5.2 version and what steps are required to store user session in database?
I had to deal with this issue myself as well. So the initial steps are as you had already mentioned in your question.
On fresh install of laravel and verify that everything works, change the SESSION_DRIVER=file to SESSION_DRIVER=database
Run the following commands IN ORDER in your console within the directory of your app:
php artisan session:table
composer dump-autoload
php artisan migrate
(This step might be different from what you did) In your config\session.php file search for:
'driver' => env('SESSION_DRIVER', 'file'),
and change it to the following
'driver' => env('SESSION_DRIVER', 'app.database'),
Within the same config\session.php file change the encrypt configuration to true
Set your connection and table name settings appropriately
'connection' => 'database_name_here',
'table' => 'sessions', //here you can change but sessions is recommended until you get more comfortable with how it all works
Attempt to login to your application and check your database to see if it all works.
If more help is needed you can also check a few resources that have helped me solve the issue. Keep in mind these resources are of people having similar issues but maybe your problem is similar to theirs. Only way to find out is to investigate. Hope this helps! =) :
https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5
https://laravel.com/docs/5.2/session
(Video tutorial on Laravel Sessions, VERY good place to help you get to where you need to be!)
https://www.youtube.com/watch?v=-FMecyZs5Cg
look it's ok to go with it manual but why don't u use the php artisan make:auth
it creates every thing u need for authentication and also helps u keeping the session instead of doing it manual ?

Laravel session database duplicate key error index

I am getting this error and any help would be greatly appreciated.
I am using mongo db as my default session database. Laravel seems to try to insert session data in table every page visit with the same session Id which generates duplicate index error.
I created my sessions table using:
php artisan session:table
composer dump-autoload
php artisan migrate
and then I set the correct properties in the app/config/sessions.php.
The first session value gets inserted correctly in the table but there is an error of duplicate index error on page refresh or redirect.
Please help.
Thanks.
I resolved the error by executing bd.sessions.drop() on the database.
https://github.com/kcbanner/connect-mongo/issues/78
The problem resolved immediately.

Getting strange errors installing a Laravel application

The first problem I'm running in to is that when installing I receive a mysql error stating that a table cannot be found. Of course it can't, I finished installing the dependencies much less run the migration. The error was being triggered by a Eloquent query in a view composer. After commenting out the entirety of my routes file Composer let me continue.
I proceed to uncomment out my route file - I get the error once again trying to run any artisan commands (can't migrate my database because I haven't migrated my database). Repeat the solution for step one and I've migrated my database.
Artisan serve is now serving me my layout file in the terminal and exiting. I'm at a bit of a loss to troubleshoot this. I assumed that it was possibly a plugin, trying to disable plugins one by one results in:
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
and being served up my layout file in the terminal.
It seems that the error is directly related to this function in my routes file:
View::composer('layouts.main', function($view) {
$things = Thing::where('stuff', 1)->orderBy('stuff')->get();
$view->with(compact('things'));
});
This isn't a new introduction to the application however so the underlying cause is coming from somewhere else.
As i said in the comment, if you are finding database errors in production server but not in local, then
check database credentials. if its ok then....
check the different configs in the environment.
using profilers(any) will let you know what environment you are in.

Resources