0
votes

How would I execute command like this from the Controller?

Package I am using that gives the below artisan commands: https://github.com/JosephSilber/page-cache

php artisan page-cache:clear {slug}

For example if typed manually:

php artisan page-cache:clear about-us

Laravel docs gives us this: https://laravel.com/docs/5.6/artisan#programmatically-executing-commands

Artisan::call('email:send', [
    'user' => 1, '--queue' => 'default'
]);

Since the artisan command page-cache:clear does not take any named parameters, how do I send the slug parameter to it?

I've tried this:

Artisan::call('page-cache:clear ' . $content->slug);

And get back this error:

Command "page-cache:clear hem" is not defined.↵↵Did you mean this?↵ page-cache:clear

I've also tried this:

Artisan::call('page-cache:clear', [$content->slug]);

But then slug is not added and it calls php artisan page-cache:clear without slug so this package clears all the cached files.

2

2 Answers

2
votes

Add explicit true as the value of the slug parameter:

Artisan::call('page-cache:clear', [$content->slug => true]);

Edit

Actually the above might only work for --name parameters and you might need this instead:

Artisan::call('page-cache:clear', ['' => $content->slug]);
2
votes

Try it
Artisan::call('page-cache:clear', ['slug' => $content->slug]);