mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-02-25 03:32:59 +01:00
76 lines
1.5 KiB
PHP
76 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Link extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
public $table = 'links';
|
|
|
|
public $fillable = [
|
|
'user_id',
|
|
'url',
|
|
'title',
|
|
'description',
|
|
'is_private',
|
|
];
|
|
|
|
/*
|
|
| ========================================================================
|
|
| SCOPES
|
|
*/
|
|
|
|
/**
|
|
* Scope for the user relation
|
|
*
|
|
* @param $query
|
|
* @param int $user_id
|
|
* @return mixed
|
|
*/
|
|
public function scopeUser($query, $user_id)
|
|
{
|
|
return $query->where('user_id', $user_id);
|
|
}
|
|
|
|
/*
|
|
| ========================================================================
|
|
| RELATIONSHIPS
|
|
*/
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\Models\User', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function category()
|
|
{
|
|
return $this->belongsTo('App\Models\Category', 'category_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function tags()
|
|
{
|
|
return $this->belongsToMany('App\Models\Tag', 'link_tags', 'link_id', 'tag_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function notes()
|
|
{
|
|
return $this->hasMany('App\Models\Note', 'link_id');
|
|
}
|
|
}
|