Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Product extends Model
- {
- protected $fillable = ['name', 'description', 'picture', 'slug'];
- public function setSlugAttribute($value)
- {
- dd($value);
- $this->attributes['slug'] = strtoupper($value);
- // replace non letter or digits by -
- $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
- // trim
- $text = trim($text, '-');
- // transliterate
- $cyr = ['а','б','в','г','д','е','ж','з','и','ѝ','й','к','л','м','н','о','п','р','с','т','у',
- 'ф','х','ц','ч','ш','щ','ъ','ь', 'ю','я','А','Б','В','Г','Д','Е','Ж',
- 'З','И','Ѝ','Й','К','Л','М','Н','О','П','Р','С','Т','У',
- 'Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ь', 'Ю', 'Я'];
- $lat = ['a','b','v','g','d','e','zh','z','i','i','y','k','l','m','n','o','p','r','s','t','u',
- 'f' ,'h' ,'ts' ,'ch','sh' ,'sht' ,'a' ,'y' ,'yu' ,'ya','A','B','V','G','D','E','Zh',
- 'Z','I','I','Y','K','L','M','N','O','P','R','S','T','U',
- 'F' ,'H' ,'Ts' ,'Ch','Sh' ,'Sht' ,'A' ,'Y' ,'Yu' , 'Ya'];
- $text = str_replace($cyr, $lat, $text);
- // lowercase
- $text = strtolower($text);
- // remove unwanted characters
- $text = preg_replace('~[^-\w]+~', '', $text);
- if (empty($text)) {
- return 'n-a';
- }
- return $text;
- }
- public function shops()
- {
- return $this->belongsToMany(Shop::class);
- }
- public function categories()
- {
- return $this->belongsToMany(Category::class);
- }
- public function production()
- {
- return $this->hasMany(Production::class);
- }
- public function houses()
- {
- return $this->belongsToMany(House::class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement