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?
Solution:Jump to solution
You could try
fn ($livewire)
but this query is also used on Edit/Create page. Best to overwrite getTableQuery()
on the ListPage19 Replies
Please someone help with this.
what is this
buyer_id
? where is it set?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
how do you provide it in the url?
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.@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
You need to define that stuff on the
ListPage
since that is the Livewire component.
And on Edit/Create accordingly if you want to use it there.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 ?
this is in ListEmailStats which extends ListRecords
Solution
You could try
fn ($livewire)
but this query is also used on Edit/Create page. Best to overwrite getTableQuery()
on the ListPageyes 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.
@mohdaftab Hi, I have the same problem, you solved this just by adding getEloquentQuery to the List?
@José Everton Hi, yes I solved it using getTableQuery().
@mohdaftab I tried using getTableQuery(), it didn't work, when you click on the pagination the url changes.
request()
won't have your site URL on a Livewire requests. Please read this thread because exactly that was explained here.I replace request() with what? Did not quite understand
I'm sorry
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.
Thanks, I'll try that!