Skip to content

Commit

Permalink
Set default translation_name and removed MissingTranslationName excep…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Flobbo authored and Flobbo committed Aug 19, 2019
1 parent 5c7e3b2 commit 12f54b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,25 +341,24 @@ a language ID or a language code.
### Basic options for translations

If you plan on using these functions for handling translations there are some
basics you need to set:
basics you need to set in your service class:

```php

use Flobbos\Crudable\Contracts\Crud;
use Flobbos\Crudable;
use Flobbos\Crudable\Contracts\Translation;

class Category implements Crud,Translation{
class CategoryService implements Crud,Translation{

use Crudable\Crudable;
use \Flobbos\Crudable\Translations\Translatable;

protected $translation_name;
protected $required_trans; //optional array of fields

public function __construct(){
$this->translation_name = 'translations';//defines the relation name
}
//only necessary if your translation relation is named something else
//than 'translations' in your model
protected $translation_name = 'my_translations';
//optional array of fields that HAVE to be present to save a translation
protected $required_trans;

}

Expand Down Expand Up @@ -444,9 +443,6 @@ This function returns an array that is then put into the save function:
if(empty($translations))
throw new MissingTranslationsException;

if(empty($this->translation_name))
throw new MissingTranslationNameException;

return $model->{$this->translation_name}()->saveMany($translations);
}

Expand Down
9 changes: 0 additions & 9 deletions src/Crudable/Exceptions/MissingTranslationNameException.php

This file was deleted.

10 changes: 6 additions & 4 deletions src/Crudable/Translations/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

use Flobbos\Crudable\Exceptions\MissingTranslationsException;
use Flobbos\Crudable\Exceptions\MissingRequiredFieldsException;
use Flobbos\Crudable\Exceptions\MissingTranslationNameException;

trait Translatable{

/**
* If you custom named your translations you can set this here
* @var string name of your translations
*/
protected $translation_name = 'translations';

/**
* Process translation input data for saving them.
* @param array $translations
Expand Down Expand Up @@ -55,9 +60,6 @@ public function saveTranslations(
if(empty($translations))
throw new MissingTranslationsException;

if(empty($this->translation_name))
throw new MissingTranslationNameException;

return $model->{$this->translation_name}()->saveMany($translations);
}

Expand Down

0 comments on commit 12f54b6

Please sign in to comment.