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

update v7 docs with last v6 changes #608

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions 7.x-dev/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ The select_multiple column will output a comma separated list of its connected e
'entity' => 'tags', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Tag', // foreign key model
// OPTIONAL
'separator' => ',', // if you want to use a different separator than the default ','
],
```

Expand Down Expand Up @@ -877,6 +879,8 @@ Show a link which opens in the new tab by default.
'type' => 'url',
'label' => 'URL',
//'target' => '_blank' // let's you change link target window.
//'element' => 'a' // let's you change the element of the link.
//'rel' => false OR 'rel' => 'noopener' // let's you disable or change the rel attribute of the link.
],
```

Expand Down
1 change: 1 addition & 0 deletions 7.x-dev/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@ CRUD::field([ // select2_from_array
'allows_null' => false,
'default' => 'one',
// 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
// 'sortable' => true, // requires the field to accept multiple values, and allow the selected options to be sorted.
]);
```

Expand Down
17 changes: 17 additions & 0 deletions 7.x-dev/crud-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,23 @@ CRUD::filter('trashed')
<a name="tips-and-tricks"></a>
## Tips and Tricks

<a name="debouncing-filters"></a>
### Add a debounce time to filters

Filters can be debounced, so that the filtering logic is only applied after the user has stopped typing for a certain amount of time. This is useful when the filtering logic is expensive and you don't want it to run on every keystroke. To debounce a filter, you can use the following code:

```php

CRUD::filter('name')
->type('text')
->debounce(1000) // debounce time in milliseconds
->whenActive(function($value) {
// CRUD::addClause('where', 'name', 'LIKE', "%$value%");
});
```

All filter types accept a `debounce`, like for example the simple filter, range filter etc.

<a name="adding-a-filter-using-array-syntax"></a>
### Adding a filter using array syntax

Expand Down
9 changes: 9 additions & 0 deletions 7.x-dev/crud-operation-clone.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class ProductCrudController extends CrudController
CRUD::setModel(\App\Models\Product::class);
CRUD::setRoute(backpack_url('product'));
CRUD::setEntityNameStrings('product', 'products');

// optionally you can redirect the user after the clone operation succeeds
// if you set the `redirect_after_clone` option to true, it defaults to the edit page
$this->crud->set('clone.redirect_after_clone', true);

// you can also use a closure to define the redirect URL
$this->crud->set('clone.redirect_after_clone', function($entry) {
return backpack_url('product/'.$entry->id.'/show'); // redirect to show view instead of edit
});
}
}
```
Expand Down
21 changes: 18 additions & 3 deletions 7.x-dev/crud-operation-list-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ a) For all CrudController (globally) in the `config/backpack/operations/list.php

b) For a specific CrudController, in its `setupListOperation()` define `CRUD::setOperationSetting('lineButtonsAsDropdown', true);`

##### Available options

Additionally you can control the dropdown behavior with `lineButtonsAsDropdownMinimum` and `lineButtonsAsDropdownShowBefore`. By default the dropdown is created no matter how many buttons are present in the line stack. You can change this behavior by setting `lineButtonsAsDropdownMinimum` to a number. If the number of buttons in the line stack is less than this number, the buttons will not be converted to a dropdown. You can also set `lineButtonsAsDropdownShowBefore` to a number to drop the buttons after that number of buttons.

```php
CRUD::setOperationSetting('lineButtonsAsDropdown', true);
CRUD::setOperationSetting('lineButtonsAsDropdownMinimum', 5); // if there are less than 5 buttons, don't create the dropdown (default: 1)
CRUD::setOperationSetting('lineButtonsAsDropdownShowBefore', 3); // force the first 3 buttons to be inline, and the rest in a dropdown (default: 0)

// in the above example, when:
// - there are 3 or less buttons, they will be shown inline
// - there are 4 buttons, all 4 will be shown inline
// - there are 5 or more buttons, the first 3 will be shown inline, and the rest in a dropdown
```

To learn more about buttons, **check out the [Buttons](/docs/{{version}}/crud-buttons) documentation page**.

<a name="filters"></a>
Expand Down Expand Up @@ -149,7 +164,7 @@ Exporting the DataTable to PDF, CSV, XLS is as easy as typing ```CRUD::enableExp

**Please note that when clicked, the button will export**
- **the _currently visible_ table columns** (except columns marked as ```visibleInExport => false```);
- **the columns that are forced to export** (with ```visibleInExport => true``` or ```exportOnlyField => true```);
- **the columns that are forced to export** (with ```visibleInExport => true``` or ```exportOnlyColumn => true```);

**In the UI, the admin can use the "Visibility" button, and the "Items per page" dropdown to manipulate what is visible in the table - and consequently what will be exported.**

Expand All @@ -159,7 +174,7 @@ Available customization:
```
'visibleInExport' => true/false
'visibleInTable' => true/false
'exportOnlyField' => true
'exportOnlyColumn' => true
```

By default, the field will start visible in the table. Users can hide it toggling visibility. Will be exported if visible in the table.
Expand All @@ -172,7 +187,7 @@ Setting `visibleInTable => true` will force the field to stay in the table no ma

Using `'visibleInTable' => false` will make the field start hidden in the table. But users can toggle it's visibility.

If you want a field that is not on table, user can't show it, but will **ALWAYS** be exported use the `exportOnlyField => true`. If used will ignore any other custom visibility you defined.
If you want a field that is not on table, user can't show it, but will **ALWAYS** be exported use the `exportOnlyColumn => true`. If used will ignore any other custom visibility you defined.

#### How to use different separator in DataTables (eg. semicolon instead of comma)

Expand Down
15 changes: 14 additions & 1 deletion 7.x-dev/crud-operation-reorder.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ This operation allows your admins to reorder & nest entries.
<a name="requirements"></a>
## Requirements

Your model should have the following integer fields, with a default value of 0: ```parent_id```, ```lft```, ```rgt```, ```depth```.
Your model should have the following integer fields, with a default value of 0: ```parent_id```, ```lft```, ```rgt```, ```depth```. The names are optional, you can change them in the ```setupReorderOperation()``` method.

```php

protected function setupReorderOperation()
{
CRUD::setOperationSetting('reorderColumnNames', [
'parent_id' => 'custom_parent_id',
'lft' => 'left',
'rgt' => 'right',
'depth' => 'deep',
]);
}
```

Additionally, the `parent_id` field has to be nullable.

Expand Down
3 changes: 2 additions & 1 deletion 7.x-dev/crud-operation-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ class Product extends Model
protected $primaryKey = 'id';
protected $fillable = ['name', 'category_id', 'options', 'price', 'tags'];
protected $translatable = ['name', 'options'];
}
```

> You DO NOT need to cast translatable string columns as array/json/object in the Eloquent model. From Eloquent's perspective they're strings. So:
Expand Down Expand Up @@ -453,4 +454,4 @@ If you want to display a **Delete** button right on the **Update** operation, yo
}
```

This will allow admins to remove entries right from the **Update Operation**, and it will redirect them back ot the **List Operation** afterwards.
This will allow admins to remove entries right from the **Update Operation**, and it will redirect them back to the **List Operation** afterwards.