-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] trashed users aren't showing up in select2_from_ajax field #1252
Comments
Based on the information provided in your bug report, it appears that you're experiencing an issue with trashed users not showing up in the The issue you're facing is similar to the one discussed in this GitHub issue, where there were problems with Here's what we can deduce from your setup:
However, the trashed spouses are still not showing up after being added and the page is refreshed. This behavior is inconsistent with what you're seeing in As a workaround, you could try modifying your protected function fetchSpouse()
{
return $this->fetch([
'model' => User::class,
'searchable_attributes' => ['lastNameFirstName'],
'paginate' => 10,
'searchOperator' => 'LIKE',
'query' => function($model) {
return $model->withTrashed()->orWhereNotNull('deleted_at');
}
]);
} This modification explicitly includes trashed records by adding If this workaround doesn't resolve the issue, it would be advisable to report this as a bug to the Backpack team, as it seems to be an inconsistency in how trashed records are handled in the For further assistance or to report this issue, you can use the Backpack community forum or open a new issue on the Backpack CRUD GitHub repository. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Github Issue (closed): [Bug] select2_from_ajax with FetchOperation doesn't work |
Hello @prescriptionlifeline if you see the data save on table, there is the spouse value? Cheers. |
Hello @prescriptionlifeline, I found the issue here. To solve, you can override the select2_from_ajax field, following these steps Then replace this line:
With:
That's should work. Cheers. |
I'll try that out after I get to work - thanks! |
I wasn't able to get this working. The only file that has I then renamed that file to zzz.select2_from_ajax.blade.php and did I then similarly renamed every select2* file and did |
I copied the fields folder to fields2 before I made my changes. I guess I copy / pasted the wrong path when I made my post. I guess everything I've ever done is now forever tainted by that and I should just throw in the towel and start flipping burgers at McDonalds 🙄
As I said in the post you're replying to, I changed that file "As a sanity check". Allow me to give another example of the concept of a sanity check. One time, many years ago, I thought I was on the prod server (this was before Docker and before Composer). I was trying to make a change directly to that server and nothing I did was showing up. I then decided, as a sanity test, I just wanted to see if I could affect any change on the prod server, even if it wasn't the one I set out to make. So then I started renaming directories. I renamed the parent directory and nothing. I renamed the And you're right - I shouldn't have to modify the vendor directory. That wasn't the point of my tests. As observed in another post, not everything can be published. Sometimes you just need to straight up copy files. I was modifying the file in the [1] For example, https://backpackforlaravel.com/docs/6.x/crud-fields#overwriting-default-field-types-1 mentions being able to publish to Anyway, I'll take a look at the rest of your post later today. The thoroughness of it does look encouraging - the less I have to fill in the gaps the less likely I am to encounter errors. |
I figured out the issue. So in the CRUD::field([
'name' => 'spouse',
'label' => 'Spouse',
'type' => 'select2_from_ajax',
'entity' => 'spouse',
'attribute' => 'name',
'data_source' => backpack_url('user/fetch/spouse'),
'method' => 'POST',
'hint' => 'Search by last name <i>or</i> first name. Adding a spouse to this account will also result in this person being added as a spouse to the spouse\'s account.',
]); In the
If it weren't for the Anyway, it turns out that adding Like I had been assuming that array keys left undefined would be inherited from the CRUD::field([
'name' => 'password',
'type' => 'password',
'attributes' => ['disabled' => 'disabled'],
'hint' => 'This field is disabled because <a tabindex="-1" href="/admin/setting/0/edit#new-user-email" target="_blank">an email with a randomly generated password</a> (eight character alpha-numeric password) will be sent out when the Save button is clicked (unless you uncheck the checkbox at the bottom of this page)'
]); ...and then I have this in CRUD::field([
'name' => 'password',
'attributes' => ['id' => 'password'],
'hint' => "<span id='passwordHint'>$hint</span>",
]); Like even though I'm not telling Laravel Backpack that the type is password in the TLDR I was making some unfounded assumptions about how the whole thing worked and your initial reply did contain the answer. I still stand by the sanity checks I performed but that's neither here nor there. Thank you for your time. |
This is worth investigating. I've re-opened this discussion so that it can be investigated a bit more 👍 Thanks for your time and for providing such a good explanation of the issue 🙏 Cheers |
Bug report
What I did
In my User CRUD I have this:
Here' my FetchOperation:
And here's my spouse method in my User model:
What I expected to happen
With all of this I can add trashed spouses to non trashed users without issue. My expectation is that the newly added members would then show up when I refresh the page.
If I do
User::findOrFail(...)->spouse
inphp artisan tinker
that returns the spouse even if the spouse isn't trashed. I just can't get theselect2_from_ajax
to behave the same way asphp artisan tinker
.What happened
After adding a trashed spouse to a non-trashed user and then refreshing the trashed spouse does not show up.
What I've already tried to fix it
I posted #1139 but I think at this point this prob needs to be seen as a bug in Laravel Backpack.
Is it a bug in the latest version of Backpack?
Yes
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: