Repository URL to install this package:
|
Version:
3.2.0 ▾
|
<?php
namespace Evsmash\Events;
use Evsmash\Core\Database\Eloquent;
use Evsmash\Core\Database\SoftDeleting;
use Evsmash\Core\Helpers\Date;
use Evsmash\Core\Simpy\Params;
use Evsmash\Events\Schemas\Events as Schema;
class Event extends Eloquent {
use SoftDeleting;
// validate
static public function validate() {
return Schema::validate();
}
// belongs to type
public function type() {
return $this->belongsTo('Evsmash\Events\EventsType');
}
// belongs to many categories
public function categories() {
return $this->belongsToMany('Evsmash\Events\EventsCategory', 'events_to_categories', 'event_id', 'category_id');
}
// has many parameters
public function parameters() {
return $this->hasMany('Evsmash\Events\EventsParameter', 'event_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', 'place']);
$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);
}
// upcomint
public function scopeUpcoming($query, $params = false) {
return $query->where('date', '>=', Date::now())->orderBy('date', 'asc');
}
// finished
public function scopeFinished($query, $params = false) {
return $query->where('date', '<', Date::now())->orderBy('date', 'desc');
}
}