-
Notifications
You must be signed in to change notification settings - Fork 920
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
[Field Type] addClause on select, select2, select_multiple, select2_multiple, checklist, checklist_dependency #47
Comments
There are a few solutions to this, available right now. Let's round them up:
Since there are 3 existing solutions to this possible problem, with option 1 being a very good one ( in my opinion) I'll go ahead and close this issue. |
hi , i have this situation
a model table containing phones models ( 5S , 6 , 7 for appel , S1 , S2 ... for samsung ) a reference table contaiing the id Schema::create('model_ref', function (Blueprint $table) { namespace App\Http\Controllers\Admin; use Backpack\CRUD\app\Http\Controllers\CrudController;
my probleme now is tha i want to be able to select brand ( marque_tel ) then only model of this brend is shown when adding reference for model many searches lead me to hasmanythrought by i dont know how to uses it with crud . and |
Just used the method @tabacitu proposes. I had a select2 with a model Cursos that I wanted filled only with activo=1 (active, boolean field) records in related models. So in the same Models\Cursos.php file (to keep things together) I added a second mini-class: class CursosActivos extends Cursos
{
public static function boot()
{
parent::boot();
static::addGlobalScope('activo', function (Builder $builder) {
$builder->where('activo', 1);
});
}
} And in my CrudController I set the select2 instead of the regular 'model' => "App\Models\Cursos" to the new filtered one 'model' => "App\Models\CursosActivos" Et voilá, my select2 combos only show active courses 😃 |
I make extension for select2 field to support filter results
|
Following @MarcosBL example, I had to do like this (probably because of a newer laravel version?) : In a separate file: <?php
namespace App\Models;
class CursosActivos extends Cursos
{
public static function boot()
{
parent::boot();
static::addGlobalScope(function ($query) {
$query->where('activo', 1);
});
}
} |
I normally create a trait and add all my fields like this. `
` and in the crud controller i include the trait using use ReOccuringFieldsTrait; |
@AurelDragut made an interesting suggestion: at some point, we'll definitely need to filter the results in these 1-n and n-n fields.
Say:
etc.
I see one way to do this right now:
But... it's not pretty... Should we do something about this? What better ways do you see to solve this?
Thanks, cheers!
The text was updated successfully, but these errors were encountered: