Laravel - reading config variable - php

I don't get it - when I search for this problem I get told to do the followng:
composer dump-autoload
php artisan config:clear
php artisan cache:clear
php artisan view:clear
And yet it is not making a difference. In my .env file:
PASS_DOMAIN=domain.local
In my /config/app.php file:
'pass_domain' => env('PASS_DOMAIN', 'example.com'),
Yet in my middleware located in /app/Http/Middleware/ if I place the following:
dd(config('pass_domain'));
I get nothing. Why cant I access this variable? Originally I had env('pass_domain') but nothing is letting me see this damn variable.
Any help?

Try this
dd(config('app.pass_domain'));

Related

Class "Route" not found after removing the configuration cache file

I ran
php artisan config:clear
Now, i am trying to run
php artisan serve
but it returns below error
Class "Route" not found in app.php at line 5.
What should I do? Thanks for your answering.
Check your app.php file in 'aliases' array this code exists or not
'Route'=> "Illuminate\Support\Facades\Route",
Remove config.php from bootstrap folder
Then run the following three commands...
php artisan clear-compiled
composer dump-autoload
php artisan optimize

impossible to show laravel debugbar with laravel 6

I have installed laravel/debugbar in my laravel 6 project, however, I don't see it displayed on my page. I have tried several things :
set APP_DEBUG=true in my .env file
run php artisan config:clear, php artisan route:clear, php artisan cache:clear, php artisan config:clear & php artisan vendor:publish
run composer dump-autoload
set enabled => true in config/debugbar.php
add the following in config/app.php
'Barryvdh\Debugbar\ServiceProvider',
'Debugbar' => 'Barryvdh\Debugbar\Facade',
Nothing helps, I still don't see the debugbar
Does somebody have an idea ? It would help an lot :)

SerializableClosure error in Laravel - Your serialized closure might have been modified and it's unsafe to be unserialized

I am getting this error in my domain where I have used laravel v8 for my site.
It shows error in line no 52 in index file:
Previously my .env file was not reading. As soon as I fixed that error I got this one now.
Please help me solve this error.
What solved it for me was running the following in my project folder:
php artisan route:clear
I also ran the below commands before the above command, but the error persisted. It only went away when I did the above. For reference, here are the commands I ran beforehand:
php artisan cache:clear
php artisan config:clear
php artisan view:clear
npm run dev
php artisan key:generate
I also want to note that I am using the following stack:
Laravel v8
Jetstream
Inertia
Vue2
This issue might occur due to change in APP_KEY value in your .env file.
APP_KEY is used for secure data transmission and Laravel recommends to do that by setting it to a random string.
This APP_KEY is used for
Encrypting cookies.
Creating the signature for signed URLs and queued closures.
Encrypting values using the encrypt() and decrypt() helpers.
A encrypted data can be decrypted if you use the same key which was used while encrypting.
So if possible look for a backup .env file and use the same APP_KEY to resolve it.
It happened to me when I replaced in production my .env file with the .env from development. It was failing because it had a different APP_KEY, so I had to generate a new APP_KEY on production.
It was solved after run these commands:
php artisan key:generate
php artisan config:cache
php artisan route:cache
php artisan view:cache
Maybe it isn't necessary to clear the views and routes.
Sometimes php artisan cache:clear doesn't work..
You should remove manually. Example
rm -rf bootstrap/cache/*.php
try this command
composer update
In vendor → .env,
change APP_URL to http://localhost.

Jwt Authentication error Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify()

I'm working on a project to learn laravel, I saw a couple of tutorials to use jwt auth in this. It was working good but now is show an error not always but I don't know why. this is it:
Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() must be an instance of Lcobucci\JWT\Signer\Key, null given, called in C:\xampp\htdocs\inmobiliaria\vendor\lcobucci\jwt\src\Signer\BaseSigner.php on line 42
Sometimes it works but not another. so I don't know what can I do. I tried with
php artisan cache:clear
php artisan config:clear
php artisan jwt:secret
but the problem still there, sometimes i get good answer from server(200) but the most part of then al bad (500).
Screenshots
Here's complete snippet
php artisan key:generate
php artisan jwt:secret
php artisan cache:clear
php artisan config:clear
Before run above commands make sure there is install jwt package, than check its config file name jwt.php in config folder.
In fact it's the right thing to solve it:
php artisan key:generate
php artisan jwt:secret
This error can occur when
JWT_SECRET is missing on the .env
JWT_SECRET is commented in the .env
The value of JWT_SECRET is wrong.
In my case, running php artisan jwt:secret it was appending the key on the current JWT_SECRET. So checking my .env file, the value of JWT_SECRET was very long and wrong (it should be 64 chars long).
To solve it:
Open the .env and remove the JWT_SECRET value (note that you have to remove it and not comment it).
Run php artisan jwt:secret
Run php artisan cache:clear && php artisan config:clear
php artisan jwt:secret
php artisan config:cache
These both command will be enough
I came across this error when I deployed my application after testing and everything else worked well on the local server.
I noticed the following;
It's possible that you are getting this error when you uploaded the applications before implementing the JWT and re-uploaded directly via the Cpanel upload without reuploading the .env file.
if this is the case, the simplest way to solve this is my merely adding the JWT:key in your .env file (at the bottom) ef
JWT_SECRET=roCZauuldMpw5i4039393939393372y98bEWumqd9ls7Uk8DEpr0gIZ6WIWB
Hope this helps :)
This can also happen when using the Laravel Vapor service if you haven't remembered to add the JWT_SECRET to the env file used by Vapor.
In that case just pull the .env file down for the current environment (in this case staging):
vapor env:pull staging
and add the JWT_SECRECT line to it, followed by a push:
vapor env:push staging
and re-deploy.
I had this problem with my Laravel 8.x and PHP 7.4 so I solved the problem by updating my keys just with these commands:
php artisan key:generate
php artisan jwt:secret
I have resolved the same on Hostinger - Shared Hosting in a bit different manner than others explained. On shared hosting's user will not have access to shell/cmd/ssh access to the server - So I have executed the commands using composer - Thanks to Ángel Carlos del Pozo Muela for sharing the idea in https://stackoverflow.com/a/48682668 for a different solution but it worked in my case here as well
I have updated the composer.json >> script tag with extra values
"scripts": {
"pre-generate-key": [
"#php artisan key:generate",
"#php artisan cache:clear",
"#php artisan config:clear"
],"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
]
Followed by that I have created a new parameter in .env file using going to hostinger file manager and deployed the changes.
JWT_SECRET={{value}}
on successful completion of deployment - Tested the all service -> all services started working fine - then I removed the "pre-generate-key" bit from composer.json and re-deployed code
i'm working on App platform - Digital Ocean php artisan jwt:secret does it for me -> it just genarates a new secret and that's what's messing (just check your .env file)
Problem Statement :
TypeError: Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() m
Facing above problem
Larave version: 8.77
Php Versionn: 7.4
Solution works 100%
php artisan key:generate
php artisan jwt:secret
php artisan cache:clear
Here is the solution it will work for me
php artisan key:generate
php artisan jwt:secret
php artisan cache:clear
php artisan config:clear
Before running the above commands make sure there is an install jwt package, then check its config file name jwt.php in the config folder

View [index] not found in laravel

my website run correctly at localhost but when i upload it on CPanel it makes a mistake and say me view index not found
InvalidArgumentException View [index] not found.
this is my Route Code:
Route::get('/', function () {
return view('index');
});
Also i executed these commands:
php artisan config:cache
php artisan config: clear
php artisan view:clear
composer update
php artisan route:clear
but it have no response!!!!!
What's your resources/views directory's permission? It should accessible by your web server.
You should try : php artisan cache:clear
If these commands work:
php artisan config:cache or php artisan
config:clear?
named your view correctly with yourview.blade.php?
placed the view correctly in the resources\views?
Maybe the problem is that your server is not setting up properly because the domain doesnt connected properly to your VPS. Contact the hosting provider.
i solved it, i upload new project and it solved but i don't know what is the issue of last project. It's so weird

Categories