Do this workflow for the very important and complicated things in your system that have many operations
Instead of mudding our controller with many operations:
class PurchasesController extends Controller
{
public function store()
{
// different
// operations
// for purchasing
// something
return redirect('/');
}
}
We can use laravel jobs:
class PurchasesController extends Controller
{
public function store()
{
dispatch(new PurchaseSomething());
return redirect('/');
}
}
// use jobs (php artisan make:job PurchaseSomething)
class PurchaseSomething extends Job
{
public function handle()
{
$this->preparePurchase()
->sendEmail();
}
protected function preparePurchase()
{
var_dump('preparing the purchase');
return $this;
}
protected function sendEmail()
{
var_dump('sending email');
return $this;
}
}