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

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

Related

Laravel vendor:publish not creating the file

Laravel "php artisan vendor:publish" not creating the config file from the package to be copied over to the main project if the file already exist. My problem is that I usually update some configs in my package and running the vendor:publish doesn't copy the file to the main app because I previously executed the command.
php artisan vendor:publish --help would show you the help information for the command. First option is
--force Overwrite any existing files
So use
php artisan vendor:publish --force
to ... overwrite existing files.

Laravel clear package auto-discovery cache of composer packages

I wanted to remove a package from laravel. I did composer remove vendor/package
It was all good on my dev, but when I deploy on production something went wrong and I cannot do anything now.
when I run
php artisan package:discover
I'm geting
In ProviderRepository.php line 208:
Class 'Laracasts\Flash\FlashServiceProvider' not found
I'm guessing I it is something to do with some kind of cache or maby config
but I cannot run this command,
php artisan config:clear
because I'm getting the same error message as above.
PS. I'm using Laravel 5.6
You may need clear the autoloader files if they get jammed up as it is looking at those cached files when php artisan config:clear runs, thus creating the jam.
Remove the following files and they will rebuild:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
I fixed my problem deleting a config file like so:
$rm bootstrap/cache/config.php
This file is basically a cache for config, if you want to have this file built for you just run a following artisan command:
$php artisan config:cache

Laravel - reading config variable

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'));

Class 'Predis\Client' not found loop

I tried all the answers here, but no luck.
The weird part is that if I simply run the command composer update I get this:
forge#development:~/default$ composer update
Cannot create cache directory /home/forge/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/forge/.composer/cache/files/, or directory is not writable. Proceeding without cache
> php artisan clear-compiled
The compiled class file has been removed.
> php artisan ide-helper:generate
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Running just php artisan ide-helper:generate gives me
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Deleting the entire vendor directory then running composer install gives me this output.
This is my composer.lock and my composer.json files.
Running the command composer require predis/predis also returns the same error:
> php artisan clear-compiled
The compiled class file has been removed.
> php artisan ide-helper:generate
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Do you have any ideas?
Update
This is a work around, but not a root solution. Running:
composer update --no-scripts
that will skip the
"scripts": {
"post-install-cmd": [
..
],
"pre-update-cmd": [
"php artisan clear-compiled",
"php artisan ide-helper:generate",
"php artisan ide-helper:models -N",
"php artisan optimize"
],
part, which is good enough for now. This indeed seems like a bug with laravel-ide-helper, reporting bug soon.
From the laravel-ide-helper readme:
When you receive a FatalException about a class that is not found, check your config (for example .... remove Redis ServiceProvider when you don't use it)
So, remove RedisServiceProvider and Redis alias from config/app.php if you don't use Redis. Then clear config cache with php artisan config:clear.

Fatal error: Class 'LaravelLocalization' not found after composer install in production

It's been 3 days since I'm working on translating my site, so I installed LaravelLocalization:
I did everything working in local, then I pushed it in production and executed:
composer install --no-interaction --no-dev
php artisan clear-compiled
php artisan optimize
composer dump-autoload -o
php artisan route:cache
php artisan config:cache
Now, all the "php artisan commands fail with:"
[Symfony\Component\Debug\Exception\FatalThrowableError]
Fatal error: Class 'LaravelLocalization' not found
In this case, in the composer install script, it fails in:
php artisan clear-compiled
I tried to run:
php artisan cache:clear
php artisan route:clear
But without any results...
Any ideas??? This is not the first time I get this kind of stuff, but I may say that this it's a pain in the ass :(
EDIT:
In my routes.php,
I deleted this line:
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']],
around all my routes, and now composer install works.
But it doesn't solve my issue, because as soon as I put it back, I still get the same error :(
I resolved it removing the line:
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']],
in my file routes.php
run again
composer install
and finally
php artisan config:clear
php artisan route:clear
What I don't know is why it happened, and if there is a way to prevent it...
as what the error says, it means that the composer can't locate your package. so be sure to
check your config/app.php file
be sure to put the package in providers and aliases arrays, respectively.
This has been a known issue for a while, but has actually finally been resolved recently. You can read about the issue here.
Basically, running php artisan loads the entire framework, including the cached files. Since the cached files don't have your service provider, you get the error. This includes running php artisan clear-compiled. So, it is using the cached files in the command that is used to delete the cached files.
This issue has finally been resolved as of laravel/framework:v5.2.25 and laravel/laravel:v5.2.27, and backported to laravel/framework:v5.1.33 and laravel/laravel:v5.1.33.
This fix includes a change to the Laravel application (laravel/laravel), in addition to the Laravel Framework (laravel/framework). To implement, you will need to:
1) Update the scripts section of your composer.json file to match that in the laravel/laravel package. Specifically:
remove the pre-update-cmd section
in the post-install-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postInstall"
in the post-update-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postUpdate"
2) Once you have updated your composer.json, run a composer update. If you only want to update the framework, you can run composer update laravel/framework.

Categories