Laravel 4 - unserialize(): Error at offset 0 of 32 bytes - laravel

When I install Laravel 4, I receive this error:
ErrorException
unserialize(): Error at offset 0 of 32 bytes
C:\xampp\htdocs\blog\laravel\bootstrap\compiled.php
return unserialize($this->stripPadding($this->mcryptDecrypt($value, $iv)));
If I modify return like this:
return unserialize(base64_decode($this->stripPadding($this->mcryptDecrypt($value, $iv))));
Then the error goes away. But of course every time I run composer update this change will be undone.
What could be the reason of this problem?
I appreciate any help.
Update: This only happens when I use Auth::check().
Update 2: Now it only works with base64_decode() removed. It's like if the xampp installation has become self-aware. Jesus!

Refer to this issue: laravel/framework#1526
A change in the encryption mechanism is the cause. My solution was to empty out the sessions and views that were cached in the storage folder, then run php artisan key:generate and relaunch the server. I'm not sure which part of the process fixed the issue, but I haven't seen it since.

The command > php artisan cache:clear fixed the problem for me.
I did not have to restart the server

Can you post what you're doing that causes this error? You shouldn't be modifying the core - because as you said, updates will overwrite it.

You have to set a news Key, use the following command:
php artisan key:generate
After that test again to run the Laravel Application
php artisan serve

Related

JWTAuth::user() returns null

I am using Laravel 8 and JWTAuth package for the api requests, often the request throws error when trying to access user info with the following line:
JWTAuth::user()->id
The error: 500 Internal Server Error
ErrorException: Trying to get property 'id' of non-object ...
The only way I could resolve this, temporary however, is to refresh the token. I am wondering that if token is expired it should say token is expired, but seems something else is happening here, which I could not figure it out.
Appreciate any help!
For anyone else facing this issue, working with tokens can quickly create caching issues which can cause headaches if not considered. So in my case resetting the JWT secrete keys fixed the issue.
php artisan jwt:secret
Also for clearing most of the cached sections:
php artisan config:clear && php artisan cache:clear && composer dump-autoload && php artisan view:clear && php artisan route:clear && npm cache clean --force

Laravel Api Documentation Genarator

I've installed the composer require mpociot/laravel-apidoc-generator according to what the documentation says.
Also published the config file
Now when I run the php artisan apidoc:generate command
I got the following error, have searched google but din't find anything relevant,
Argument 1 passed to Mpociot\ApiDoc\Tools\DocumentationConfig::__construct() must be of the type array, null given, called in D:\WaheedSindhani\Projects\petApp\vendor\mpociot\laravel-apidoc-generator \src\Commands\GenerateDocumentation.php on line 61
it is a config cache problem
php artisan config:clear has solved the problem'

Laravel ER diagram generator getAllModelsFromEachDirectory()

When I try to follow the instruction here (https://github.com/beyondcode/laravel-er-diagram-generator) I get the following error.
Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory() must be of the type array, null given, called in vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php on line 96
at vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:101
97|
98| return $modelsFromDirectories;
99| }
100|
101| protected function getAllModelsFromEachDirectory(array $directories): Collection
102| {
103| return collect($directories)
104| ->map(function ($directory) {
105| return $this->modelFinder->getModelsInDirectory($directory)->all();
Exception trace:
1 BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:96
2 BeyondCode\ErdGenerator\GenerateDiagramCommand::getModelsThatShouldBeInspected()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:57
Please use the argument -v to see more details.
I've already opened an issue in the repository.
Screen capture of the error:
Posting for others that may encounter same issue.
Confirm you are using the latest version 1.4.0 of the library
Also if you're using php artisan serve try to stop the server. Run php artisan config:cache, and restart the artisan sever.
Note that the reason why you might need to run php artisan config:cache is because Laravel does cache the app's configurations. if you changed or added new configurations you might explicitly need to clear the configuration cache so that Laravel can cache the new configurations.
If no solution yet. Try this
php artisan vendor:publish --provider=BeyondCode\\ErdGenerator\\ErdGeneratorServiceProvider.
Then repeat step 2.

Error while migrating from Laravel tinker console (sqlite)

Consider
laravel new bug
Then adding in .env
DB_CONNECTION=sqlite
DB_DATABASE=/home/me/Code/bug/storage/database.sqlite
creating database
touch /home/me/Code/bug/storage/database.sqlite
migrating
php artisan migrate && php artisan migrate:fresh
Now trying to migrate programmatically in tinker
php artisan tinker
>> Artisan::call('migrate');
First time resulting in => 0 (as expected ?) But second time:
>>> Artisan::call('migrate:fresh')
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]:
General error: 17 database schema has changed (SQL: select * from
sqlite_master where type = 'table' and name = migrations)'
Artisan::call('migrate')
Third time:
Symfony\Component\Console\Exception\CommandNotFoundException with
message 'There are no commands defined in the "migrate" namespace.'
Any ideas whats going on here? Can you reproduce?
Update using postgres. The second time running Artisan::call('migrate:fresh') I get:
Symfony\Component\Console\Exception\CommandNotFoundException with
message 'There are no commands defined in the "migrate" namespace.'
UPDATE 2: Issue filed here: https://github.com/laravel/framework/issues/22997
https://github.com/laravel/tinker/issues/37
I don't think if this is a laravel bug, but I found your problem:
Calling a non existing command like Artisan::call('migrate:fresh') will crash. The reason is a typo: tinker does not accept fresh, only refresh. Calling the command via tinker will empty the sqllite file so you can't execute any commands until you migrate without tinker.
Here are my steps:
php artisan migrate # sqllite file is filled with content
php artisan tinker
> Artisan:call('refresh')
> Artisan::call('fresh') # now the sqllite file is empty
> Artisan::call('migrate') # will crash
php artisan migrate
> Artisan::('refresh') # works
so I think it's a tinker bug, not a laravel one. Tinker is doing some kind of snapshot (If you change a Model you have to restart tinker to call it there), maybe the error handling is not implemented is the best way to catch all errors.

issue with composer when deploying using Envoyer

I'm having trouble deploying my laravel app using envoyer, the error accuer in installing composer dependencies, here it is:
Generating autoload files
Illuminate\Foundation\ComposerScripts::postInstall
php artisan optimize
[RuntimeException]
No supported encrypter found. The cipher and / or key length are invalid.
it's my first time and I'm having lots of errors and don't really know how to fix them , I'd appreciate the help thanks
You need to generate key using command php artisan generate:key
As .env is not present in production so change app.php under config file to Something like below
'key' => env('APP_KEY','base64:42KCuY7E8Zc+JHrUZFyta4yspqLAjcVZeZVvymrjZBI=')
This would solve your problem.

Resources