1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-25 03:32:59 +01:00
LinkAce/app/Models/Link.php

115 lines
3.1 KiB
PHP
Raw Normal View History

2018-08-23 00:01:54 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
2018-08-23 13:33:56 +02:00
/**
* Class Link
*
* @package App\Models
* @property int $id
* @property int $user_id
* @property int|null $category_id
* @property string $url
* @property string $title
* @property string|null $description
* @property int $is_private
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \App\Models\Category|null $category
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Note[] $notes
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Tag[] $tags
* @property-read \App\Models\User $user
*/
2018-08-23 00:01:54 +02:00
class Link extends Model
{
use SoftDeletes;
public $table = 'links';
public $fillable = [
'user_id',
2018-08-23 10:39:03 +02:00
'category_id',
2018-08-23 00:01:54 +02:00
'url',
'title',
'description',
'is_private',
];
/*
| ========================================================================
| SCOPES
*/
/**
* Scope for the user relation
*
* @param $query
* @param int $user_id
* @return mixed
*/
public function scopeByUser($query, $user_id)
2018-08-23 00:01:54 +02:00
{
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');
}
/*
| ========================================================================
| METHODS
*/
/**
* @return null|string
*/
public function tagsForInput()
{
$tags = $this->tags;
if ($tags->isEmpty()) {
return null;
}
return $tags->implode('name', ',');
}
2018-08-23 00:01:54 +02:00
}