This is unnecessary, but I'm just curious.
I created a Job class and removed all Queue traits so it could be dispatched only synchronously. The only traits are:
class SyncJob{
use Dispatchable, SerializesModels;
Not it can return data from handle() when I dispatch it via dispatchSync:
$models = SyncJob::dispatchSync();
The job returns models with pagination wrapped into a JsonResource collection:
public function handle()
{
$models = SomeModel::paginate(20);
return MyModelResrouce::collection($models);
}
But in this case, the collection has no pagination data.
If I do the same in a controller method, it works fine and contains all pagination data:
public function index()
{
$models = SomeModel::paginate(20);
return response()->json(MyModelResrouce::collection($models););
}
Obviously, it's due to use of a Job class. Is it possible to keep/add the pagination data when returning a resource collection from a Job class?