Hi Team,
Kinda new to Laravel and even newer to Livewire. I'm working to build out an application and loving the journey so far. Really enjoying Laravel!
Before I 'discovered' Livewire pagination, I was producing a very large HTML table based on a MySQL table. In its simplest form, I was just doing $things=Things::get(); passing $things to the blade and then iterating through $things as $thing and producing that honking great HTML table.
I found Livewire pagination and was quickly able to implement it by doing Things::paginate() and the other stuff and it works just dandy.
As my app developed, I wanted to enrich that table. 'Things' have owners (represented on the things table as an owner ID). The 'owners' table has the full ID, Name, email, phone# etc. I want some of that reference data including on the HTML table.
Before Livewire pagination, in the controller, I'd slurp in the entire 'things' table to $things and 'owners' table into $owners. Then, I'd build a new array by iterating through $things in an outer loop and then through owners until there's a match on the id field. Idea being that the resulting array would have something like:
$resultingArray['0']['thingName']="small widget";
$resultingArray['0']['owner']="Fred Smith";
$resultingArray['1']['thingName']="big widget";
$resultingArray['1']['owner']="Sarah Jones";
I pass $resultingArray to the blade and produce the table from there. Hope I'm making sense so far.
My question is: How do I use Livewire pagination on this resulting array - or elsewise achieve same?
I've tried Googleing for and answer but I'm not sure I'm getting my search terms right. Hopefully, by being a bit more expressive here, I'm getting my question across!
My guess is that I need to use Eloquent ORM to do the joining replicating that $resultingArray and then sticking paginate() on the end? Figured I'd ask quickly here if I'd be on the right track before investing time learning all that. Or am I missing something!?
cheers all!