<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mindtwo / laravel-dynamic-model-mutators example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use mindtwo\LaravelDynamicModelMutators\DynamicModelMutator;
class User extends Model
{
use DynamicModelMutator;
}
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
static::registerSetMutator('translations', 'setAttributeTranslation');
static::registerGetMutator('translations', 'getAttributeTranslation');
}
namespace Examples;
use Illuminate\Database\Eloquent\Model;
use mindtwo\LaravelDynamicModelMutators\DynamicModelMutator;
use mindtwo\LaravelDynamicModelMutators\Interfaces\DynamicModelMutatorInterface;
class exampleModel extends Model implements DynamicModelMutatorInterface
{
use use DynamicModelMutator;
$translations = [
'attribute_1',
'attribute_2',
'attribute_3'
];
}
namespace Examples;
use Illuminate\Database\Eloquent\Model;
use mindtwo\LaravelDynamicModelMutators\DynamicModelMutator;
use mindtwo\LaravelDynamicModelMutators\Interfaces\DynamicModelMutatorInterface;
class exampleModel extends Model implements DynamicModelMutatorInterface
{
use use DynamicModelMutator;
$translations = [
'attribute_1' = 'string',
'attribute_2' = 'text',
'attribute_3' = [
'type' => string,
'locales' => ['en', 'de']
]
];
}
/**
* Set attribute translation.
*
* @return void
*/
public function setAttributeTranslation($name, $value, $config=null)
{
// Set value $value for attribute $name
}
/**
* Get attribute translation.
*
* @return void
*/
public function setAttributeTranslation($name, $config=null)
{
// Get value for attribute $name
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.