mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-04-19 06:27:00 +02:00
Optimize public scopes for links, lists and tags
This commit is contained in:
parent
26b232dfde
commit
805ed2ac03
@ -17,7 +17,7 @@ class LinkController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$links = Link::privateOnly(false)
|
||||
$links = Link::publicOnly()
|
||||
->with('tags')
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'created_at'),
|
||||
|
@ -17,7 +17,7 @@ class ListController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$lists = LinkList::isPrivate(false)
|
||||
$lists = LinkList::publicOnly()
|
||||
->withCount('links')
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'name'),
|
||||
@ -41,10 +41,10 @@ class ListController extends Controller
|
||||
*/
|
||||
public function show(Request $request, $listID): View
|
||||
{
|
||||
$list = LinkList::isPrivate(false)->findOrFail($listID);
|
||||
$list = LinkList::publicOnly()->findOrFail($listID);
|
||||
|
||||
$links = $list->links()
|
||||
->privateOnly(false)
|
||||
->publicOnly()
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'title'),
|
||||
$request->input('orderDir', 'asc')
|
||||
|
@ -17,7 +17,7 @@ class TagController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$tags = Tag::isPrivate(false)
|
||||
$tags = Tag::publicOnly()
|
||||
->withCount('links')
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'name'),
|
||||
@ -42,7 +42,7 @@ class TagController extends Controller
|
||||
*/
|
||||
public function show(Request $request, $tagID): View
|
||||
{
|
||||
$tag = Tag::isPrivate(false)->findOrFail($tagID);
|
||||
$tag = Tag::publicOnly()->findOrFail($tagID);
|
||||
|
||||
$links = $tag->links()
|
||||
->privateOnly(false)
|
||||
|
@ -39,7 +39,8 @@ use Venturecraft\Revisionable\RevisionableTrait;
|
||||
* @property Collection|Tag[] $tags
|
||||
* @property User $user
|
||||
* @method static Builder|Link byUser($user_id)
|
||||
* @method static Builder|Link privateOnly($is_private)
|
||||
* @method static Builder|Link privateOnly()
|
||||
* @method static Builder|Link publicOnly()
|
||||
* @method static MorphMany revisionHistory()
|
||||
*/
|
||||
class Link extends Model
|
||||
@ -106,12 +107,22 @@ class Link extends Model
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param bool $isPrivate
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopePrivateOnly($query, bool $isPrivate)
|
||||
public function scopePrivateOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', $isPrivate);
|
||||
return $query->where('is_private', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopePublicOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', false);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -155,6 +166,10 @@ class Link extends Model
|
||||
| ========================================================================
|
||||
| METHODS
|
||||
*/
|
||||
public function getMarkdownDescriptionAttribute()
|
||||
{
|
||||
return Str::markdown($this->description, ['html_input' => 'strip']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL shortened to max 50 characters
|
||||
|
@ -27,7 +27,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @property-read Collection|Link[] $links
|
||||
* @property-read User $user
|
||||
* @method static Builder|Tag byUser($user_id)
|
||||
* @method static Builder|Tag isPrivate(bool $private)
|
||||
* @method static Builder|Tag privateOnly()
|
||||
* @method static Builder|Tag publicOnly()
|
||||
*/
|
||||
class LinkList extends Model
|
||||
{
|
||||
@ -70,21 +71,31 @@ class LinkList extends Model
|
||||
* @param int $user_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeByUser($query, $user_id)
|
||||
public function scopeByUser(Builder $query, $user_id)
|
||||
{
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for selecting private or non-private lists
|
||||
* Scope for selecting private lists only
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param bool $is_private
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeIsPrivate($query, bool $is_private)
|
||||
public function scopePrivateOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', $is_private);
|
||||
return $query->where('is_private', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for selecting public lists only
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopePublicOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', false);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -26,7 +26,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @property-read Collection|Link[] $links
|
||||
* @property-read User $user
|
||||
* @method static Builder|Tag byUser(int $user_id)
|
||||
* @method static Builder|Tag isPrivate(bool $private)
|
||||
* @method static Builder|Tag publicOnly()
|
||||
* @method static Builder|Tag privateOnly()
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
@ -74,15 +75,25 @@ class Tag extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for selecting private or non-private tags
|
||||
* Scope for selecting private tags only
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param bool $is_private
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeIsPrivate($query, bool $is_private)
|
||||
public function scopePrivateOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', $is_private);
|
||||
return $query->where('is_private', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for selecting public tags only
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopePublicOnly(Builder $query)
|
||||
{
|
||||
return $query->where('is_private', false);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5,12 +5,12 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": "^7.3 | ^8.0",
|
||||
"kovah/laravel-html-meta": "^1.0",
|
||||
"composer/semver": "^1.5",
|
||||
"doctrine/dbal": "^2.10.2",
|
||||
"fideloper/proxy": "^4.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"kovah/laravel-html-meta": "^1.0",
|
||||
"laracasts/flash": "^3.1",
|
||||
"laravel/fortify": "^1.7",
|
||||
"laravel/framework": "^8.0",
|
||||
|
2
composer.lock
generated
2
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "970e7c41642a1817c593f6f2a9423513",
|
||||
"content-hash": "7ec84e953e5721f52aa0761a13441037",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
Loading…
x
Reference in New Issue
Block a user