2014-11-24 16:49:07 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Models;
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
use AltThree\Validator\ValidatingTrait;
|
2015-01-01 12:23:17 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2015-01-02 00:53:23 +00:00
|
|
|
use Illuminate\Support\Str;
|
2014-11-27 14:11:09 +00:00
|
|
|
|
2015-01-01 12:23:17 +00:00
|
|
|
class IncidentTemplate extends Model
|
2014-12-20 21:20:17 +00:00
|
|
|
{
|
2014-11-27 16:05:00 +00:00
|
|
|
use ValidatingTrait;
|
2014-11-27 14:11:09 +00:00
|
|
|
|
2015-01-01 18:57:33 +00:00
|
|
|
/**
|
2015-08-22 15:57:53 +01:00
|
|
|
* The attributes that should be casted to native types.
|
2015-01-01 18:57:33 +00:00
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2015-08-22 15:57:53 +01:00
|
|
|
protected $casts = [
|
|
|
|
'id' => 'int',
|
|
|
|
'name' => 'string',
|
|
|
|
'template' => 'string',
|
2014-12-20 20:58:10 +00:00
|
|
|
];
|
|
|
|
|
2015-01-01 18:57:33 +00:00
|
|
|
/**
|
|
|
|
* The fillable properties.
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2015-01-01 12:23:17 +00:00
|
|
|
protected $fillable = ['name', 'template'];
|
2014-11-24 16:49:07 +00:00
|
|
|
|
2015-08-22 15:57:53 +01:00
|
|
|
/**
|
|
|
|
* The validation rules.
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
public $rules = [
|
|
|
|
'name' => 'required',
|
|
|
|
'template' => 'required',
|
|
|
|
];
|
|
|
|
|
2014-12-20 20:36:15 +00:00
|
|
|
/**
|
|
|
|
* Overrides the models boot method.
|
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public static function boot()
|
|
|
|
{
|
2014-11-27 16:05:00 +00:00
|
|
|
parent::boot();
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
self::saving(function ($template) {
|
2014-11-27 16:05:00 +00:00
|
|
|
$template->slug = Str::slug($template->name);
|
|
|
|
});
|
|
|
|
}
|
2015-11-12 14:55:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a template by the slug.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Query\Builder $query
|
|
|
|
* @param string $slug
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Query\Builder
|
|
|
|
*/
|
|
|
|
public function scopeForSlug($query, $slug)
|
|
|
|
{
|
|
|
|
return $query->where('slug', $slug);
|
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|