Sometimes I write down some stuff I find interesting…
Speeding up Laravel Jobs
When going through the Laravel Queue documentation, I noticed a section around Queued Relationships and the d-low is that essentially when you’re sending a model to a Job, if your model has relationships loaded, those relationships will also get loaded into the payload of the job. This isn’t always obvious! For example, take the below Job as an example: use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class WelcomeEmailJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public function __construct(public User $user) { } public function handle() { // Some sending logic here... } } Because we’re expecting a User model its seralized, including the relations. ...