Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trogne's avatar

after migrate:refresh, always have to run cache:clear to see the view composer data

Everytime I run "migrate:refresh", I always then have to run "cache:clear" to see the view composer data, in this case the "channels":

AppServierProvider.php :

    public function boot()
    {
        \View::composer('*', function ($view){
            $channels = \Cache::rememberForever('channels', function (){
                return Channel::all(); 
            });
            $view->with('channels', $channels);
        });

After "migrate:refresh" and with tinker "factory('App\Thread', 30)->create();", I don't see the channels.

I have to run "cache:clear". The instructor (Jeffrey), does not run "cache:clear".

0 likes
13 replies
Snapey's avatar

Seems correct to me, since you have cached Channel::all forever ?

trogne's avatar

Yes it is cache forever, so why I have to re-run cache:clear ?

The instructor is not doing cache:clear.

The data should still be there after a migrate:refresh

Snapey's avatar

What cache driver are you using?

Snapey's avatar

your factory creates new channels? Are they faked (ie, different each time?)

What tutorial of Jeffrey' are you referring to?

trogne's avatar

He does migrate:refresh, then creates new threads. When a thread is created, it creates an associated thread in the process. After his thread creation, his channels cache still works, not mine.

Snapey's avatar

So after seeding, aren't the channels all named differently? How is having the old cached channels of any use as they will have wrong names?

Snapey's avatar

When you run migrate:refresh why is the cache table not empty?

Have you checked what it contains before and after migrate:refresh

Are you sure you are using database for cache?

trogne's avatar

Even though I'm refreshing the channels table with "migrate:refresh" and "tinker factory create threads", the already cached "channels" should be retrievable if I die dump the "channels" from a view. It's empty.

Strange.

Maybe a bug with laravel cache and homestead on windows ?!?

trogne's avatar
trogne
OP
Best Answer
Level 3

Solution was to start the migrations from scratch : migrate:fresh instead of migrate:refresh

Please or to participate in this conversation.