display create button by condition

hello i want to display create button of header by condition how should i do that? i tried to customize the function in the image but i got error, i don't know the proper way for saying this. any help will be usefull
No description
Solution:
I would simply just add a query?
return MyModel::where('user_id', auth()->id())->count() < 1;
return MyModel::where('user_id', auth()->id())->count() < 1;
...
Jump to solution
7 Replies
toeknee
toeknee8mo ago
You should use Laravel Policies really once youn have the policy we inherit it naturally. you are doing $this->id but that's always going to be false isn't it... What are you trying to do? What condition should create button be shown.
matin rajabi
matin rajabiOP8mo ago
how to say the condition in this function? i want to show the button when the table is empty and there is no record in it
toeknee
toeknee8mo ago
Is this a relationship manager?
matin rajabi
matin rajabiOP8mo ago
no it's a simple resource. i want user can create new record just when he never create any record
Solution
toeknee
toeknee8mo ago
I would simply just add a query?
return MyModel::where('user_id', auth()->id())->count() < 1;
return MyModel::where('user_id', auth()->id())->count() < 1;
matin rajabi
matin rajabiOP8mo ago
oh man how could i miss such a simple thing?!! thanks a lot for your time
toeknee
toeknee8mo ago
No problem.
Want results from more Discord servers?
Add your server