2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Product extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'ab_product';
|
|
|
|
protected $with = ['descriptions'];
|
|
|
|
|
|
|
|
public function descriptions()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProductTranslate::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Service::class);
|
|
|
|
}
|
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
public function getProductIdAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('#%04s',$this->id);
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
/**
|
|
|
|
* Get the language name
|
|
|
|
*
|
|
|
|
* @param Language $lo
|
2018-08-01 07:09:38 +00:00
|
|
|
* @return string Product Name
|
2018-05-20 12:53:14 +00:00
|
|
|
*/
|
|
|
|
public function name(Language $lo)
|
|
|
|
{
|
|
|
|
return $this->descriptions->where('language_id',$lo->id)->first()->name;
|
|
|
|
}
|
|
|
|
}
|