Skip to content

Commit

Permalink
Merge pull request #497 from Laravel-Backpack/replace-$this->crud-wit…
Browse files Browse the repository at this point in the history
…h-CRUD

replace $this->crud->addClause by CRUD::addClause
  • Loading branch information
pxpm authored Aug 14, 2023
2 parents bb33e3e + ce47e96 commit 790ccec
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions 6.x/crud-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CRUD::filter('active')
CRUD::filter('active')
->type('simple')
->whenActive(function ($value) {
$this->crud->addClause('where', 'active', '1');
CRUD::addClause('where', 'active', '1');
});
```

Expand All @@ -96,19 +96,19 @@ CRUD::filter('active')
CRUD::filter('active')
->type('simple')
->whenActive(function ($value) {
$this->crud->addClause('where', 'active', '1');
CRUD::addClause('where', 'active', '1');
})->whenInactive(function ($value) {
$this->crud->addClause('where', 'active', '0');
CRUD::addClause('where', 'active', '0');
})->apply();

// else alias, left to be applied by the operation itself
CRUD::filter('active')
->type('simple')
->label('Simple')
->whenActive(function ($value) {
$this->crud->addClause('where', 'active', '1');
CRUD::addClause('where', 'active', '1');
})->else(function ($value) {
$this->crud->addClause('where', 'active', '0');
CRUD::addClause('where', 'active', '0');
});
```

Expand Down Expand Up @@ -199,7 +199,7 @@ Only shows a label and can be toggled on/off. Useful for things like active/inac
CRUD::filter('active')
->type('simple')
->whenActive(function() {
// $this->crud->addClause('active'); // apply the "active" eloquent scope
// CRUD::addClause('active'); // apply the "active" eloquent scope
});
```

Expand All @@ -216,7 +216,7 @@ Shows a text input. Most useful for letting the user filter through information
CRUD::filter('description')
->type('text')
->whenActive(function($value) {
// $this->crud->addClause('where', 'description', 'LIKE', "%$value%");
// CRUD::addClause('where', 'description', 'LIKE', "%$value%");
});
```

Expand All @@ -234,7 +234,7 @@ Show a datepicker. The user can select one day.
CRUD::filter('birthday')
->type('date')
->whenActive(function($value) {
// $this->crud->addClause('where', 'date', $value);
// CRUD::addClause('where', 'date', $value);
});
```

Expand All @@ -252,8 +252,8 @@ CRUD::filter('from_to')
->type('date_range')
->whenActive(function($value) {
// $dates = json_decode($value);
// $this->crud->addClause('where', 'date', '>=', $dates->from);
// $this->crud->addClause('where', 'date', '<=', $dates->to . ' 23:59:59');
// CRUD::addClause('where', 'date', '>=', $dates->from);
// CRUD::addClause('where', 'date', '<=', $dates->to . ' 23:59:59');
});
```

Expand All @@ -276,7 +276,7 @@ CRUD::filter('status')
4 => 'Not available',
])
->whenActive(function($value) {
// $this->crud->addClause('where', 'status', $value);
// CRUD::addClause('where', 'status', $value);
});
```

Expand All @@ -302,7 +302,7 @@ CRUD::filter('status')
];
})
->whenActive(function($value) {
// $this->crud->addClause('where', 'status', $value);
// CRUD::addClause('where', 'status', $value);
});
```

Expand All @@ -329,7 +329,7 @@ CRUD::filter('status')
];
})
->whenActive(function($value) {
// $this->crud->addClause('whereIn', 'status', json_decode($values));
// CRUD::addClause('whereIn', 'status', json_decode($values));
});
```

Expand Down Expand Up @@ -366,7 +366,7 @@ CRUD::filter('category_id')
->values(backpack_url('product/fetch/category'))
->method('POST')
->whenActive(function($value) {
// $this->crud->addClause('where', 'category_id', $value);
// CRUD::addClause('where', 'category_id', $value);
});

// other methods
Expand Down Expand Up @@ -404,7 +404,7 @@ CRUD::filter('category_id')
->type('select2_ajax')
->values(url('admin/test/ajax-category-options'))
->whenActive(function($value) {
// $this->crud->addClause('where', 'category_id', $value);
// CRUD::addClause('where', 'category_id', $value);
});

// other methods:
Expand All @@ -431,10 +431,10 @@ CRUD::filter('number')
->whenActive(function($value) {
$range = json_decode($value);
// if ($range->from) {
// $this->crud->addClause('where', 'number', '>=', (float) $range->from);
// CRUD::addClause('where', 'number', '>=', (float) $range->from);
// }
// if ($range->to) {
// $this->crud->addClause('where', 'number', '<=', (float) $range->to);
// CRUD::addClause('where', 'number', '<=', (float) $range->to);
// }
});

Expand All @@ -455,7 +455,7 @@ CRUD::filter('category_id')
->type('view')
->view('package::columns.column_type_name') // or path to blade file
->whenActive(function($value) {
// $this->crud->addClause('where', 'category_id', $value);
// CRUD::addClause('where', 'category_id', $value);
});
```

Expand Down Expand Up @@ -601,7 +601,7 @@ Use a simple filter to add a scope if the filter is active:
CRUD::filter('published')
->type('simple')
->whenActive(function() { // if the filter is active (the GET parameter "published" exits)
$this->crud->addClause('published');
CRUD::addClause('published');
});
```

Expand Down Expand Up @@ -637,11 +637,11 @@ $this->crud->addFilter([
],
false, // the simple filter has no values, just the "Draft" label specified above
function() { // if the filter is active (the GET parameter "draft" exits)
$this->crud->addClause('where', 'draft', '1');
CRUD::addClause('where', 'draft', '1');
// we've added a clause to the CRUD so that only elements with draft=1 are shown in the table
// an alternative syntax to this would have been
// $this->crud->query = $this->crud->query->where('draft', '1');
// another alternative syntax, in case you had a scopeDraft() on your model:
// $this->crud->addClause('draft');
// CRUD::addClause('draft');
});
```

0 comments on commit 790ccec

Please sign in to comment.