I use Laravel 5.8, and as we know, there are 3 type of cache in Laravel
Config cache (php artisan config:cache)
Route cache (php artisan route:cache)
View cache (php artisan view:cache)
.
So, in my Laravel app, I use Cache::remember('mycachetoday', $seconds, function(){})...
In order to clear the mycachetoday, i must run php artisan cache:clear, right?
But I wonder if I run php artisan cache:clear, will the config, route, and view cache be cleared also?
Thanks
You can try
php artisan config:cache
The config cache file will be store in bootstrap/cache directory.
When you run
php artisan cache:clear
It will only clear the datas that you store by Cache. The config cache file still in bootstrap/cache.
After you run php artisan config:clear, the file will be deleted from bootstrap/cache.
Check the ClearCommand source code, there is no code that delete any config/route/view cache file in bootstrap/cache, and only clear the application cache.
/**
* Execute the console command.
*
* #return void
*/
public function handle()
{
$this->laravel['events']->dispatch(
'cache:clearing', [$this->argument('store'), $this->tags()]
);
$successful = $this->cache()->flush();
$this->flushFacades();
if (! $successful) {
return $this->error('Failed to clear cache. Make sure you have the appropriate permissions.');
}
$this->laravel['events']->dispatch(
'cache:cleared', [$this->argument('store'), $this->tags()]
);
$this->info('Application cache cleared!');
}
Check the ConfigClearCommand source code, it will delete the config cache file.
/**
* Execute the console command.
*
* #return void
*/
public function handle()
{
$this->files->delete($this->laravel->getCachedConfigPath());
$this->info('Configuration cache cleared!');
}
To clear everything, you can do php artisan optimize:clear. This will result in:
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!
Regards!
Related
after running php artisan serve my project is running on http://127.0.0.1:8000/.
I am inserting files on logo folder my inserting code is
$request->file('logo')->store('logo', 'public');
this code is inserting files inside \storage\app\public\logo\
Now when I try to view this file in image there is no image showing
my image view code is
http://127.0.0.1:8000/storage/logo/eoFICKlGoU8yDoJrLGYfKFsx6Yq4uGvDs5yC9WQ7.png
my filesystem default is 'default' => env('FILESYSTEM_DISK', 'public'),
also in the env it FILESYSTEM_DISK = public
I have tried
php artisan config:clear
php artisan storage:link
php artisan optimize:clear
But still failed to show the image in . Please help I have tried many method available on stackoverflow
Simply run, php artisan storage:link.
The problem might be that your storage is not linked to your public folder.
I have this error one production env. only on some routes, I see no difference between the routes that works and the few of them that don't work. All my routes are in web.php, and in front I try to access via Vuejs/Axios.
Also, the both url from error when I try to access them I get to https://, even if I try http:// , I get redirect to https.
What I tried till now.
.env
APP_URL=https://my.url
web.php
URL::forceScheme('https'); //at the top of the file
App/Providers/AppServiceProvider
public function boot()
{
URL::forceScheme('https');
}
Also:
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:clear
php artisan config:cache
npm run prod
I found a strange solution.
I changed the route name from random_question to random, also the controller method name that was show to random and works.
I have used Laravel queues in my application and when i try to run
php artisan queue:restart
it gives me following exception:
ErrorException : file_put_contents(/storage/framework/cache/data/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90): failed to open stream: No such file or directory
at /var/www/html/asd/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
118| * #return int
119| */
120| public function put($path, $contents, $lock = false)
121| {
> 122| return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
123| }
124|
125| /**
126| * Prepend to a file.
Exception trace:
1 file_put_contents("/var/www/html/asd/storage/framework/cache/data/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90", "9999999999i:1558912298;")
/var/www/html/asd/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
2 Illuminate\Filesystem\Filesystem::put("/var/www/html/asd/storage/framework/cache/data/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90", "9999999999i:1558912298;")
/var/www/html/asd/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php:65
Please use the argument -v to see more details.
I have tried running following commands but to no avail:
composer dump-autoload
php artisan optimize
php artisan clear-compiled
php artisan cache:clear
php artisan view:clear
php artisan route:cache
I am not able to reflect changes made to my application logic that is in queue handlers, any help in this regard is much appreciated.
You forgot to run php artisan config:cache with the other commands
I read somewhere else that you could try
chmod 775 -R storage
In staging and production environment, when I try to get my custom defined variable from .env file, it returns null. I have tried creating new Key for APP and cleared all sort of caches, but result is same.
APP_NAME="App - Staging"
APP_ENV=staging
APP_KEY=<HIDDEN_KEY>
APP_DEBUG=true
APP_LOG_LEVEL=none
APP_URL=https://staging.app.com
APP_BASE_URL="https://app-staging.app.com"
Clearing Cache
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:cache
But when using following in blade view gets nothing
env('APP_BASE_URL') returns null
It is because you have run php artisan config:cache. If you are using config:cache, your env() calls should only be made in your config files.
See here: https://laravel.com/docs/5.6/configuration#configuration-caching
This post solved my issue, I defined custom config in config/app.php
https://laracasts.com/discuss/channels/laravel/accessing-custom-environment-variable
/*
|-------------------------------------------------------------------------
| Custom config variables
|-----------
|
*/
'base_url' => env('APP_BASE_URL', 'http://localhost'),
Then in .env I definded:
APP_BASE_URL="https://app-staging.app.com"
Finally cleared the cache, worked.
In blade view
{{ config('app.base_url') }}
Yes it will return only null
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.
See the laravel documentation https://laravel.com/docs/5.6/configuration#configuration-caching
I'm looking to refresh and seed a single table in Laravel 5.1. Is this even possible?
I have tried the below, but it gives an error (incorrect syntax).
php artisan migrate:refresh --path=database/migrations/CreateTableTimesheet
If I use: php artisan migrate:refresh it just says:
Nothing to migrate
You could use migrate:refresh command that will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database :
php artisan migrate:refresh
And you may use the --class option to specify a specific seeder class to run individually :
php artisan db:seed --class=UserTableSeeder
The full code will be :
php artisan migrate:refresh
php artisan db:seed --class=UserTableSeeder
Hope this helps.
Its better to truncate your same table first and then seed:-
public function run()
{
Table::truncate();
//seed your table here
}
then you can run your same seeder like this:-
php artisan db:seed --class=YourSeeder
Maybe first just backup the database, drop it and check if whole seeding, migrating and refreshing mechanic works. But first dump artisan autoload.
I don't think any answer so far addresses the question of migrating and seeding a single table. So, given the migration file database/migrations/create_foo_table.php and the seed file database/seeds/FooTableSeeder.php, which contains the FooTableSeeder seed class, you can do the following:
php artisan migrate:refresh --path=database/migrations/create_foo_table.php
php artisan db:seed --class=FooTableSeeder
This will rollback, migrate and seed your Foo table. See: rolling back migrations and running seeders in the Laravel 5.1 documentation (at the time of writing this, Laravel 7.x is out and the syntax has not changed).
php artisan tinker
>>> App\Status::truncate()
Will clear the statuses table
So you can do
>>> App\{MODEL_CLASS}::truncate()
I found this quite useful when I don't want to clear all the tables, especially users.
include full table name
example
php artisan migrate:refresh --path='database/migrations/2014_10_12_000000_create_table_timesheet.php'
You can do it in two steps:
Refresh your specific table:
php artisan migrate:refresh --path=database/migrations/00_create_foo_table.php
Seed tables set in database/seeds/DatabaseSeeder.php:
composer dump-autoload
php artisan db:seed
=== Extra information ===
You can comment the seeders you don't want to use in DatabaseSeeder.php:
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* #return void
*/
public function run()
{
$this->call([
FooSeeder::class,
// BarSeeder::class,
// UserSeeder::class,
]);
}
}
In this example, only database/seeds/FooSeeder.php will be passed.