Cachet/app/Models/IncidentTemplate.php

81 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Models;
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
{
use ValidatingTrait;
2014-11-27 14:11:09 +00:00
2015-01-01 18:57:33 +00:00
/**
* The attributes that should be casted to native types.
2015-01-01 18:57:33 +00:00
*
* @var string[]
*/
protected $casts = [
'name' => 'string',
'slug' => 'string',
'template' => 'string',
2014-12-20 20:58:10 +00:00
];
2015-01-01 18:57:33 +00:00
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = ['name', 'slug', 'template'];
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'template' => 'required|string',
];
2014-12-20 20:36:15 +00:00
/**
* Overrides the models boot method.
2016-12-15 20:11:06 +00:00
*
* @return void
2014-12-20 20:36:15 +00:00
*/
2014-12-20 21:20:17 +00:00
public static function boot()
{
parent::boot();
2014-12-20 21:20:17 +00:00
self::saving(function ($template) {
if (!$template->slug) {
$template->slug = Str::slug($template->name);
}
});
}
/**
* Finds a template by the slug.
*
* @param string $slug
* @param string[] $columns
*
* @return \Illuminate\Database\Query\Builder
*/
public static function forSlug($slug, $columns = ['*'])
{
2016-10-19 12:29:16 +01:00
$template = static::where('slug', '=', $slug)->firstOrFail($columns);
return $template;
}
}