To pass the page slug variable from the controller to Livewire, you can use Livewire's mount method. In the controller, you can pass the slug as a parameter to the Livewire component and then retrieve it in the mount method. Here's an example:
Controller:
public function getProfiloVote($slug) {
$profile = XIPB_Core_Members::where('members_seo_name', $slug)->firstOrFail();
$staff = User::where('slug', $slug)->first();
if (app('setting')['debug'] == 'false') {
setLocation('Visualizzando il profilo di '. $profilo->name);
}
return view('front.pages.user.main', compact('staff', 'profilo', 'slug'));
}
Livewire:
class ProfileVote extends Component
{
use WithPagination;
public $slug;
public function mount($slug)
{
$this->slug = $slug;
}
public function paginationView()
{
return 'livewire.pagination';
}
public function render()
{
$profile = XIPB_Core_Members::where('members_seo_name', $this->slug)->firstOrFail();
$item = VotoGiochi::where('id_utente', $profile->member_id)
->paginate(10);
return view('livewire.profile-vote', [
'item' => $item
]);
}
}
In the Livewire component, we define a public property $slug and use the mount method to retrieve the slug passed from the controller. We can then use this slug to retrieve the $profile object in the render method and use its member_id property to retrieve the VotoGiochi records.