weird error in middleware when using select2_from_ajax with FetchOperation #1123
-
In my UserCrudController I have this field: CRUD::field([
'name' => 'spouse',
'label' => 'Spouse',
'type' => 'select2_from_ajax',
'entity' => 'spouse',
'attribute' => 'lastNameFirstName',
'data_source' => backpack_url('user/fetch/spouse'),
'method' => 'POST',
]); (lastNameFirstName is a generated column). Here's the FetchOperation method I added to the Crud controller: protected function fetchSpouse()
{
return $this->fetch([
'model' => User::class, // required
'searchable_attributes' => ['lastNameFirstName'],
'paginate' => 10, // items to show per page
'searchOperator' => 'LIKE',
'query' => function($model) {
return $model->withTrashed();
} // to filter the results that are returned
]);
} Here's the method in my User model: public function spouse()
{
return $this->hasOne(User::class, 'spouseID');
} Anyway, when I add a spouse and hit the Save button I get an error from one of the middleware I've defined in config/backpack/base.php, which doesn't make any sense to me. In particular, I'm getting this error:
Here's the middleware that's giving that error: https://github.com/Laravel-Backpack/CRUD/blob/6.7.15/src/app/Http/Middleware/CheckIfAdmin.php It's the If I leave the Spouse field blank I don't get that error - I only get it if I fill that field in. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@prescriptionlifeline When that error throws, you have a Open that dropdown and there you can find where the error is actually thrown. The fact that it shows that middleware is because Backpack stack is initialized in a middleware. Alternatively you can click on the top righ "Share", and share the full error report with us. Let me know if that helps. |
Beta Was this translation helpful? Give feedback.
The solution was to change my relationship in my User model: