Skip to content
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

[Feature] Conditionable trait #420

Merged
merged 5 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions 5.x/crud-fluent-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ CRUD::field('products')
->tab('Others');
```

<a name="fluent-fields-conditionable-methods"></a>
### Conditionable methods

Sometimes you may need a method to be chained on a field based on another condition. Backpack takes advantage of <a href="https://laravel.com/docs/10.x/queries#conditional-clauses" target="_blank">Laravel Conditionable</a> to easily let you accomplish that. You can either use ```->when()``` or ```unless()```:

```php
CRUD::field('email')
->label('Email')
->when($condition, function ($field) {
$field->hint('My hint');
});
```

<a name="fluent-columns-api"></a>
## Fluent Columns

Expand Down Expand Up @@ -242,6 +255,20 @@ CRUD::column('name')->makeFirst();
CRUD::column('name')->makeLast();
```

<a name="fluent-columns-conditionable-methods"></a>
### Conditionable methods

Sometimes you may need a method to be chained on a column based on another condition. Backpack takes advantage of <a href="https://laravel.com/docs/10.x/queries#conditional-clauses" target="_blank">Laravel Conditionable</a> to easily let you accomplish that. You can either use ```->when()``` or ```unless()```:
```php
CRUD::column('name')
->unless($condition, function ($column) {
$column->wrapper([
'href' => function ($crud, $column, $entry, $related_key) {
return backpack_url('category/'.$related_key.'/show');
},
])
});
```

<a name="fluent-columns-examples"></a>
### Examples
Expand Down Expand Up @@ -375,6 +402,21 @@ CRUD::button('name')->makeFirst();
CRUD::button('name')->makeLast();
```

<a name="fluent-buttons-conditionable-methods"></a>
### Conditionable methods

Sometimes you may need a method to be chained on a button based on another condition. Backpack takes advantage of <a href="https://laravel.com/docs/10.x/queries#conditional-clauses" target="_blank">Laravel Conditionable</a> to easily let you accomplish that. You can either use ```->when()``` or ```unless()```:

```php
CRUD::button('name')
->unless($condition, function ($button) {
$button->before('description')
->when($secondCondition, , function ($button) {
$button->forget('suffix');
});
});
```


<a name="fluent-buttons-examples"></a>
### Examples
Expand Down Expand Up @@ -565,6 +607,17 @@ CRUD::filter('name')->makeFirst();
CRUD::filter('name')->makeLast();
```

<a name="fluent-filters-conditionable-methods"></a>
### Conditionable methods

Sometimes you may need a method to be chained on a filter based on another condition. Backpack takes advantage of <a href="https://laravel.com/docs/10.x/queries#conditional-clauses" target="_blank">Laravel Conditionable</a> to easily let you accomplish that. You can either use ```->when()``` or ```unless()```:

```php
CRUD::filter('name')
->when($condition, function ($filter) {
$filter->remove();
});
```

<a name="fluent-filters-examples"></a>
### Examples
Expand Down