You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.8 KiB
81 lines
1.8 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Outlet extends Model
|
|
{
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'address', 'latitude', 'longitude', 'creator_id',
|
|
];
|
|
|
|
/**
|
|
* The accessors to append to the model's array form.
|
|
*
|
|
* @var array
|
|
*/
|
|
public $appends = [
|
|
'coordinate', 'map_popup_content',
|
|
];
|
|
|
|
/**
|
|
* Get outlet name_link attribute.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getNameLinkAttribute()
|
|
{
|
|
$title = __('app.show_detail_title', [
|
|
'name' => $this->name, 'type' => __('outlet.outlet'),
|
|
]);
|
|
$link = '<a href="'.route('outlets.show', $this).'"';
|
|
$link .= ' title="'.$title.'">';
|
|
$link .= $this->name;
|
|
$link .= '</a>';
|
|
|
|
return $link;
|
|
}
|
|
|
|
/**
|
|
* Outlet belongs to User model relation.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get outlet coordinate attribute.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function getCoordinateAttribute()
|
|
{
|
|
if ($this->latitude && $this->longitude) {
|
|
return $this->latitude.', '.$this->longitude;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get outlet map_popup_content attribute.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getMapPopupContentAttribute()
|
|
{
|
|
$mapPopupContent = '';
|
|
$mapPopupContent .= '<div class="my-2"><strong>'.__('outlet.name').':</strong><br>'.$this->name_link.'</div>';
|
|
$mapPopupContent .= '<div class="my-2"><strong>'.__('outlet.coordinate').':</strong><br>'.$this->coordinate.'</div>';
|
|
|
|
return $mapPopupContent;
|
|
}
|
|
}
|