Skip to content
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
19 changes: 13 additions & 6 deletions 6.x/crud-operation-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,6 @@ class Product extends Model
use CrudTrait;
use HasTranslations;

/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/

protected $table = 'products';
protected $primaryKey = 'id';
protected $fillable = ['name', 'category_id', 'options', 'price', 'tags'];
Expand All @@ -383,6 +377,19 @@ class Product extends Model

Change the languages available to translate to/from, in your crud config file (```config/backpack/crud.php```). By default there are quite a few enabled (English, French, German, Italian, Romanian).


#### Updating and creating translatable entries

When you're creating a translatable entry, the entry will be created in the current user app locale. Either the one set in `config/app.php` or if you allow your admins to change the panel locale, the one set by them will be used.

When you update a translatable entry you choose in what language you want to create the translation for, idependently of the panel language or app locale.

When the entry has no translations in the chosen language for translation, you will get the option to select another language to copy the translations from.


![https://backpackforlaravel.com/uploads/docs/translatable-bar.png](https://backpackforlaravel.com/uploads/docs/translatable-bar.png)


Additionally, if you have slugs (but only if you need translatable slugs), you'll need to use backpack's classes instead of the ones provided by `cviebrock/eloquent-sluggable`.
Make sure you have `cviebrock/eloquent-sluggable` installed as well, if not, please do it with `composer require cviebrock/eloquent-sluggable`:

Expand Down
27 changes: 14 additions & 13 deletions 7.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ CRUD::field([ // Checklist
'pivot' => true,
'show_select_all' => true, // default false
// 'number_of_columns' => 3,

]);
```

Expand Down Expand Up @@ -874,7 +874,7 @@ CRUD::field([

#### Uploading files with summernote

Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote Uploader](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote Uploader](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
Input preview:

![CRUD Field - summernote](https://backpackforlaravel.com/uploads/docs-4-2/fields/summernote.png)
Expand Down Expand Up @@ -1153,22 +1153,22 @@ CRUD::field([ // Address google
]);
```

Using Google Places API is dependent on using an API Key. Please [get an API key](https://console.cloud.google.com/apis/credentials) - you do have to configure billing, but you qualify for $200/mo free usage, which covers most use cases. Then copy-paste that key as your ```services.google_places.key``` value.
Using Google Places API is dependent on using an API Key. Please [get an API key](https://console.cloud.google.com/apis/credentials) - you do have to configure billing, but you qualify for $200/mo free usage, which covers most use cases. Then copy-paste that key as your ```services.google_places.key``` value.

**IMPORTANT NOTE**: Your key needs access to the following APIS:
- Maps JavaScript API;
- Places API;
- Geocoding API.

While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.

So inside your ```config/services.php``` please add the items below:
```php
'google_places' => [
'key' => 'the-key-you-got-from-google-places'
],
```
Alternatively you can set the key in your field definition, but we do **not recommend** it:
Alternatively you can set the key in your field definition, but we do **not recommend** it:
```php
[
'name' => 'google_field',
Expand Down Expand Up @@ -1445,7 +1445,7 @@ Using Google Places API is dependent on using an API Key. Please [get an API key
- Places API;
- Geocoding API.

While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.

**How to save in multiple inputs?**

Expand Down Expand Up @@ -1791,7 +1791,7 @@ CRUD::field([

By default Backpack does not allow you to select the same pivot twice. If you want to allow the selection of the same pivot more than once you should take some setup steps before. Follow along with the steps below:

**1)** Make sure your pivot table has a unique key, usually an auto-increment id. If you don't have one, you can add it with a migration.
**1)** Make sure your pivot table has a unique key, usually an auto-increment id. If you don't have one, you can add it with a migration.

**2)** Add the `id` to your `->withPivot()` fields on your relation. Eg:
```php
Expand All @@ -1816,7 +1816,7 @@ CRUD::field([
'name' => 'companies',
'type' => 'relationship',
'allow_duplicate_pivots' => true,
'subfields' => // your subfields (do not add `id` as a subfield. That's done automatically by Backpack).
'subfields' => // your subfields (do not add `id` as a subfield. That's done automatically by Backpack).
]);
```

Expand Down Expand Up @@ -2179,8 +2179,9 @@ CRUD::field([ // select2_from_array
'options' => ['one' => 'One', 'two' => 'Two'],
'allows_null' => false,
'default' => 'one',
// 'multiple' => true, // allows multiple selections
// '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;
// 'sortable' => true, // requires the field to accept multiple values, and allow the selected options to be sorted.
// 'tagging' => true, // allow users to type and create new options.
]);
```
Expand Down Expand Up @@ -2369,7 +2370,7 @@ CRUD::field([
'minimum_input_length' => 2, // minimum characters to type before querying results
'multiple' => true, // allow multiple selections
'include_all_form_fields' => false, // only send the current field through AJAX (for a smaller payload if you're not using multiple chained select2s)

// OPTIONAL - if the response is a list of objects (and not a simple array)
'attribute' => 'title', // attribute to show in the select2
'attributes_to_store' => ['id', 'title'], // attributes to store in the database
Expand Down Expand Up @@ -2420,7 +2421,7 @@ public function fetchAirports()

#### Storing only one the id in the database

A very common use case you may have is to store only the id of the selected item in the database instead of a `json` string. For those cases you can achieve that by setting the `attributes_to_store` attribute to an array with only one item, the id of the selected item and do a little trick with the model events to store the id you want, and to give the field that id in a way it understands.
A very common use case you may have is to store only the id of the selected item in the database instead of a `json` string. For those cases you can achieve that by setting the `attributes_to_store` attribute to an array with only one item, the id of the selected item and do a little trick with the model events to store the id you want, and to give the field that id in a way it understands.

```php

Expand All @@ -2429,7 +2430,7 @@ CRUD::field([
'type' => 'select2_json_from_api',
'name' => 'airport_id', // dont make your column json if not storing json on it!
// .... the rest your field configuration
'attribute' => 'id',
'attribute' => 'id',
'attributes_to_store' => ['id'],
'events' => [
'saving' => function($entry) {
Expand All @@ -2446,7 +2447,7 @@ CRUD::field([

### slug <span class="badge badge-pill badge-info">PRO</span>

Track the value of a different text input and turn it into a valid URL segment (aka. slug), as you type, using Javascript. Under the hood it uses [slugify](https://github.com/simov/slugify/blob/master/README.md) to generate the slug with some sensible defaults.
Track the value of a different text input and turn it into a valid URL segment (aka. slug), as you type, using Javascript. Under the hood it uses [slugify](https://github.com/simov/slugify/blob/master/README.md) to generate the slug with some sensible defaults.

```php
CRUD::field([ // Text
Expand Down
15 changes: 14 additions & 1 deletion 7.x/crud-operation-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class ProductCrudController extends CrudController
}
```

>But before you do that, ask yourself - **_is this something that should be done when an entry is added/updated/deleted from the application, too_**? Not just the admin admin? If so, a better place for it would be the Model. Remember your Model is a pure Eloquent Model, so the cleanest way might be to use [Eloquent Event Observers](https://laravel.com/docs/12.x/eloquent#events) or [accessors and mutators](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators).
>But before you do that, ask yourself - **_is this something that should be done when an entry is added/updated/deleted from the application, too_**? Not just the admin admin? If so, a better place for it would be the Model. Remember your Model is a pure Eloquent Model, so the cleanest way might be to use [Eloquent Event Observers](https://laravel.com/docs/5.5/eloquent#events) or [accessors and mutators](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators).

<a name="translatable-models"></a>
### Translatable models and multi-language CRUDs
Expand Down Expand Up @@ -383,6 +383,19 @@ class Product extends Model

Change the languages available to translate to/from, in your crud config file (```config/backpack/crud.php```). By default there are quite a few enabled (English, French, German, Italian, Romanian).


#### Updating and creating translatable entries

When you're creating a translatable entry, the entry will be created in the current user app locale. Either the one set in `config/app.php` or if you allow your admins to change the panel locale, the one set by them will be used.

When you update a translatable entry you choose in what language you want to create the translation for, idependently of the panel language or app locale.

When the entry has no translations in the chosen language for translation, you will get the option to select another language to copy the translations from.


![https://backpackforlaravel.com/uploads/docs/translatable-bar.png](https://backpackforlaravel.com/uploads/docs/translatable-bar.png)


Additionally, if you have slugs (but only if you need translatable slugs), you'll need to use backpack's classes instead of the ones provided by `cviebrock/eloquent-sluggable`.
Make sure you have `cviebrock/eloquent-sluggable` installed as well, if not, please do it with `composer require cviebrock/eloquent-sluggable`:

Expand Down