Repository URL to install this package:
|
Version:
3.2.0 ▾
|
<?php
namespace Evsmash\Companies;
use Evsmash\Core\Database\Eloquent;
use Evsmash\Core\Database\SoftDeleting;
use Evsmash\Core\Dec\Dec;
use Evsmash\Core\Input\Route;
use Evsmash\Core\Simpy\Params;
use Evsmash\Companies\Schemas\Companies as Schema;
class Company extends Eloquent {
use SoftDeleting;
// validate
static public function validate() {
return Schema::validate();
}
// belongs to type
public function type() {
return $this->belongsTo('Evsmash\Companies\CompaniesType');
}
// belongs to many categories
public function categories() {
return $this->belongsToMany('Evsmash\Companies\CompaniesCategory', 'companies_to_categories', 'company_id', 'category_id');
}
// params
public function scopeParams($query, $params = false) {
$scope = new Params();
$scope->scope($query, $params);
$scope->where('promoted');
$scope->where('published');
$scope->where('type', 'type_id');
$scope->search(['name', 'slug', 'content', 'sneak']);
$scope->order(['created_at' => 'desc']);
$scope->with(['type', 'categories']);
return $scope->query;
}
// published
public function scopePublished($query, $params = false) {
return $query->where('published', 1);
}
// promoted
public function scopePromoted($query, $params = false) {
return $query->where('promoted', 1);
}
// map
public function getMapAttribute() {
if(!empty($this->lat) AND !empty($this->lng)) {
$map = [];
$map['latitude'] = $this->lat;
$map['longitude'] = $this->lng;
$map['html']['content'] = $this->name.'<br />'.$this->address.'<br />'.Dec::a(Route::map('evsmash/companies/companies/show').'/'.$this->id.'/'.$this->slug, 'More');
return $map;
}
}
// ribbon
public function getRibbonAttribute() {
// promoted
if(cfg('evsmash-companies-ribbons-promoted')) {
if($this->promoted == 1) {
return '<span class="ribbon ribbon-promoted">'.cfg('evsmash-companies-ribbons-promoted').'</span>';
}
}
// no ribbons
return false;
}
}