F
Filamentβ€’2w ago
frame

Query string null in a relationmanager

I can read request()->query('group') in ViewUser::getTitle just fine but in UserResource's ResultsRelationManager it returns null. Is there a way to read URL query strings in a relationmanager, or some other way to pass data from Resource to Relationmanager? I need to alter both UserResource infolist and the ResultsRelationManager table under it based on this query string. πŸ€”
Solution:
in your relation manager if you would add property $group and set it as Url livewire attribute. does it work then? ```php use Livewire\Attributes\Url; #[Url]...
Jump to solution
10 Replies
krekas
krekasβ€’2w ago
what's this group is in url? where it comes from?
frame
frameOPβ€’2w ago
Better to create a custom resource pageπŸ‘
krekas
krekasβ€’2w ago
still curious what is that group, where it comes from and what you are trying to do
frame
frameOPβ€’2w ago
Filter relationmanager rows by two columns, User and Group. So $record would be User but then I need to also pass Group so I need to pass that by query string in URL, for example UserResource::getUrl('view', ['record' => $record, 'group_id' => $group->id])
krekas
krekasβ€’2w ago
does group belong to the record?
frame
frameOPβ€’2w ago
belongstomany
krekas
krekasβ€’2w ago
you could maybe get group from a owner record
Solution
krekas
krekasβ€’7d ago
in your relation manager if you would add property $group and set it as Url livewire attribute. does it work then?
use Livewire\Attributes\Url;

#[Url]
public int|null $group = null;
use Livewire\Attributes\Url;

#[Url]
public int|null $group = null;
and call it where needed like $this->group then
frame
frameOPβ€’7d ago
Hey! Yeah i did something like that. Setting group as a property worked and also helped debug another problem I had, this time with custom pages πŸ˜… https://discord.com/channels/883083792112300104/1327240818855252000/1327250122551201852
public Group $group;
public User $user;
public function mount(string $record): void
{
$groupUuid = request()->query('group');
$this->group = Group::where('uuid', $groupUuid)->firstOrFail();
$this->record = $this->resolveRecord($record);
$this->user = $this->record; // So user is always available in `$table->query`
}
public Group $group;
public User $user;
public function mount(string $record): void
{
$groupUuid = request()->query('group');
$this->group = Group::where('uuid', $groupUuid)->firstOrFail();
$this->record = $this->resolveRecord($record);
$this->user = $this->record; // So user is always available in `$table->query`
}
Using #[Url] to optimize line count further might be a good idea πŸ‘

Did you find this page helpful?