blue-twilight/app/Label.php
2017-09-10 12:52:41 +01:00

33 lines
611 B
PHP

<?php
namespace App;
use App\Helpers\MiscHelper;
use Illuminate\Database\Eloquent\Model;
class Label extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'url_alias'
];
public function generateAlias()
{
$this->url_alias = preg_replace('/[^a-z0-9\-]/', '-', strtolower($this->name));
}
public function photos()
{
return $this->belongsToMany(Photo::class, 'photo_labels');
}
public function url()
{
return route('viewLabel', $this->url_alias);
}
}