how to access public variable in getEloquentQuery

Hello, I am using getEloquentQuery and adding request()->buyer_id in the query and it works fine but when I use sorting it just disappears the data unless I hard code the buyer_id to the query. My question is how do I put the buyer_id in a public variable and access it in getEloquentQuery function please?
No description
Solution:
You could try fn ($livewire) but this query is also used on Edit/Create page. Best to overwrite getTableQuery() on the ListPage
Jump to solution
19 Replies
mohdaftab
mohdaftabOP12mo ago
Please someone help with this.
krekas
krekas12mo ago
what is this buyer_id? where is it set?
mohdaftab
mohdaftabOP12mo ago
it is basically the belongsto id in buyer_contact table what i am looking for is to provide the buyer_id in url parameter and be able to use in the getEloquentquery, which works fine by using request()->buyer_id but when I use sorting or searching in that table it just changes the url parameters and the results are gone, I have to refresh again to get the data again. i just need this to be able to access the buyer_id variable which is initiated at the construct or mount function so I don't have to change it again or use request()->buyer_id everytime
krekas
krekas12mo ago
how do you provide it in the url?
Dennis Koch
Dennis Koch12mo ago
It's not working because Livewire requests have a different URL. You could overwrite the mount() method and store the value on a public property to access it later.
mohdaftab
mohdaftabOP12mo ago
@Dennis Koch this is exactly what I need to do but getEloquentquery function isn't recognizing those public properties $this isn't working either can not use $this in a non-object context
Dennis Koch
Dennis Koch12mo ago
You need to define that stuff on the ListPagesince that is the Livewire component. And on Edit/Create accordingly if you want to use it there.
mohdaftab
mohdaftabOP12mo ago
yes I used ListPage to get the value of buyer_id but I am using getEloquentquery on the resource page, is it possible to use the public property from ListPage into resource page please ?
mohdaftab
mohdaftabOP12mo ago
this is in ListEmailStats which extends ListRecords
No description
Solution
Dennis Koch
Dennis Koch12mo ago
You could try fn ($livewire) but this query is also used on Edit/Create page. Best to overwrite getTableQuery() on the ListPage
mohdaftab
mohdaftabOP12mo ago
yes that sounds good, I will try with getTableQuery in ListPage now. Thank you, I hope I will be able to make it work. @Dennis Koch it works great thank you so much.
José Everton
José Everton5mo ago
@mohdaftab Hi, I have the same problem, you solved this just by adding getEloquentQuery to the List?
mohdaftab
mohdaftabOP5mo ago
@José Everton Hi, yes I solved it using getTableQuery().
José Everton
José Everton5mo ago
@mohdaftab I tried using getTableQuery(), it didn't work, when you click on the pagination the url changes.
José Everton
José Everton5mo ago
No description
No description
No description
Dennis Koch
Dennis Koch5mo ago
request() won't have your site URL on a Livewire requests. Please read this thread because exactly that was explained here.
José Everton
José Everton5mo ago
I replace request() with what? Did not quite understand I'm sorry
Dennis Koch
Dennis Koch5mo ago
You need to store the data to a Livewire property on mount. That can be used on Livewire requests afterwards. If that's unclear, best to start a new thread with what issues you are facing.
José Everton
José Everton5mo ago
Thanks, I'll try that!
Want results from more Discord servers?
Add your server