Move models to their own subdirectory
This commit is contained in:
parent
2c5b0f3ab5
commit
2a0d188313
67 changed files with 82 additions and 86 deletions
61
app/Models/Tag.php
Normal file
61
app/Models/Tag.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
/**
|
||||
* We shall set a blacklist of non-modifiable model attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Define the relationship with tags.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public function notes()
|
||||
{
|
||||
return $this->belongsToMany('App\Models\Note');
|
||||
}
|
||||
|
||||
/**
|
||||
* The bookmarks that belong to the tag.
|
||||
*/
|
||||
public function bookmarks()
|
||||
{
|
||||
return $this->belongsToMany('App\Models\Bookmark');
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize tags so they’re lowercase and fancy diatrics are removed.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public function setTagAttribute($value)
|
||||
{
|
||||
$this->attributes['tag'] = $this->normalize($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method actually normalizes a tag. That means lowercase-ing and
|
||||
* removing fancy diatric characters.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public static function normalize($tag)
|
||||
{
|
||||
return mb_strtolower(
|
||||
preg_replace(
|
||||
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
|
||||
'$1',
|
||||
htmlentities($tag)
|
||||
),
|
||||
'UTF-8'
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue