Closed tabacitu closed 3 years ago
Questions:
This can probably be avoided by actually creating the CrudColumn object only after the last definition. I remember we did something like that inside the CrudFilter
object, where we automatically call apply()
. Basically to call addColumn
inside CrudColumn
only after everything is defined. But... that involves refactoring how CrudColumn
works, and we might break some other things (many other things), so I'm skeptical of doing this. Any other workarounds?
Isn't there anything extra we can do before calling the method, to make sure it's a relationship? Something to determine if that method should be called or not?
What can we do as a workaround for people that still want to use the fluent syntax and run into this problem? If we decide "it's a known issue" and we have a workaround for the array syntax... we should also have one for the fluent syntax. And right now we don't... Right now I'm thinking of like asking the user to define $relationships
on the Model and if a Model has $relationships
but the method isn't there... we don't call it. But that sounds pretty freakin' broad, and it has the potential of conflicting with the entity's own relationships
methods/attributes.
Not sure what we can do here... Thoughts anyone?
Shouldn't scopes be defined by: public function scopeXXXX($query) { ... }
and then $query->xxxx()->first()
?
Haha - right 🤦♂️ me stoopid sometimes. Thanks @pxpm - there's no real issue here, sorry for wasting your time.
Bug report
What I did
Inside a
Comment
model, I have both ahidden
attribute, and ahidden
local scope:I've created a CRUD for it, and inside the ListOperation I've tried to add a column for the
hidden
attribute of each entry:What I expected to happen
The column to show up.
What happened
The ListOperation throws a nasty error when trying to load the page:
Too few arguments to function Backpack\CommentManager\Models\Comment::hidden(), 0 passed in /Users/tabacitu/Sites/backpackforlaravel/vendor/backpack/crud/src/app/Library/CrudPanel/CrudPanel.php on line 355 and exactly 1 expected
What happens is that the
hidden()
scope is called - instead of using the column in the db.Rephrased:
CRUD::column()
callsBackpack\CRUD\app\Library\CrudPanel\CrudPanel::makeSureColumnHasNeededAttributes()
;$this->makeSureColumnHasModel($column);
$this->getRelationModel($column['entity']);
that fails in
CrudPanel
, line 355:It's a problem we've talked about before - if a method exists on the model, and you add a column/field for it, we assume it's a relationship. That's because not all relationship methods return a proper type, so we can't know for sure if it's a relationship - so we assume it is. Which sounded fine at the time.
At the time, we thought that... if the user gets into this predicament, they'd just define
'entity' => false
and it would no longer try to see if it's a relationship. But. That doesn't work using the fluent syntax.What I've already tried to fix it
CRUD::column('hidden')->entity(false)->type('check');
- but that doesn't work, still throws the same error because what happens is that the CRUD does add the column as normal (assumes relationship), and only afterwards tries to changeentity
tofalse
.What does work is defining that column using the array syntax:
That's because (using the array syntax) the first thing that gets added is with
entity
set tofalse
.Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is: