mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-01-17 21:28:30 +01:00
Make By User Scope Shorter
This commit is contained in:
parent
80a8a1ba10
commit
a84d38173b
@ -21,7 +21,7 @@ class LinkController extends Controller
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$links = Link::byUser(auth()->id())
|
||||
$links = Link::byUser()
|
||||
->orderBy(
|
||||
$request->input('order_by', 'created_at'),
|
||||
$request->input('order_dir', 'DESC')
|
||||
|
@ -21,7 +21,7 @@ class ListController extends Controller
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$lists = LinkList::byUser(auth()->id())
|
||||
$lists = LinkList::byUser()
|
||||
->orderBy(
|
||||
$request->input('order_by', 'created_at'),
|
||||
$request->input('order_dir', 'DESC')
|
||||
|
@ -21,7 +21,7 @@ class TagController extends Controller
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$tags = Tag::byUser(auth()->id())
|
||||
$tags = Tag::byUser()
|
||||
->orderBy(
|
||||
$request->input('order_by', 'created_at'),
|
||||
$request->input('order_dir', 'DESC')
|
||||
|
@ -18,22 +18,22 @@ class DashboardController extends Controller
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$recentLinks = Link::byUser(auth()->user()->id)
|
||||
$recentLinks = Link::byUser()
|
||||
->latest()
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
$recentTags = Tag::byUser(auth()->user()->id)
|
||||
$recentTags = Tag::byUser()
|
||||
->latest()
|
||||
->limit(25)
|
||||
->get();
|
||||
|
||||
$recentLists = LinkList::byUser(auth()->user()->id)
|
||||
$recentLists = LinkList::byUser()
|
||||
->latest()
|
||||
->limit(15)
|
||||
->get();
|
||||
|
||||
$brokenLinks = Link::byUser(auth()->user()->id)
|
||||
$brokenLinks = Link::byUser()
|
||||
->where('status', '>', 1)
|
||||
->count();
|
||||
|
||||
|
@ -23,19 +23,19 @@ class TrashController extends Controller
|
||||
public function index(): View
|
||||
{
|
||||
$links = Link::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
|
||||
$lists = LinkList::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
|
||||
$tags = Tag::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
|
||||
$notes = Note::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
|
||||
return view('app.trash.index', [
|
||||
|
@ -27,7 +27,7 @@ class FetchController extends Controller
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$tags = Tag::byUser(auth()->user()->id)
|
||||
$tags = Tag::byUser()
|
||||
->where('name', 'like', '%' . escapeSearchQuery($query) . '%')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
@ -59,7 +59,7 @@ class FetchController extends Controller
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$tags = LinkList::byUser(auth()->user()->id)
|
||||
$tags = LinkList::byUser()
|
||||
->where('name', 'like', '%' . escapeSearchQuery($query) . '%')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
@ -92,7 +92,7 @@ class FetchController extends Controller
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$link = Link::byUser(auth()->user()->id)
|
||||
$link = Link::byUser()
|
||||
->where('url', trim($query))
|
||||
->where('id', '!=', $request->input('ignore_id', 0))
|
||||
->first();
|
||||
|
@ -29,7 +29,7 @@ class LinkController extends Controller
|
||||
session()->put('links.index.orderBy', $orderBy);
|
||||
session()->put('links.index.orderDir', $orderDir);
|
||||
|
||||
$links = Link::byUser(auth()->id())
|
||||
$links = Link::byUser()
|
||||
->with('tags')
|
||||
->orderBy($orderBy, $orderDir)
|
||||
->paginate(getPaginationLimit());
|
||||
|
@ -28,7 +28,7 @@ class ListController extends Controller
|
||||
session()->put('lists.index.orderBy', $orderBy);
|
||||
session()->put('lists.index.orderDir', $orderDir);
|
||||
|
||||
$lists = LinkList::byUser(auth()->id())
|
||||
$lists = LinkList::byUser()
|
||||
->withCount('links')
|
||||
->orderBy($orderBy, $orderDir);
|
||||
|
||||
@ -88,7 +88,7 @@ class ListController extends Controller
|
||||
public function show(Request $request, LinkList $list): View
|
||||
{
|
||||
$links = $list->links()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'created_at'),
|
||||
$request->input('orderDir', 'desc')
|
||||
|
@ -28,7 +28,7 @@ class TagController extends Controller
|
||||
session()->put('tags.index.orderBy', $orderBy);
|
||||
session()->put('tags.index.orderDir', $orderDir);
|
||||
|
||||
$tags = Tag::byUser(auth()->id())
|
||||
$tags = Tag::byUser()
|
||||
->withCount('links')
|
||||
->orderBy($orderBy, $orderDir);
|
||||
|
||||
@ -88,7 +88,7 @@ class TagController extends Controller
|
||||
*/
|
||||
public function show(Request $request, Tag $tag): View
|
||||
{
|
||||
$links = $tag->links()->byUser(auth()->id())
|
||||
$links = $tag->links()->byUser()
|
||||
->orderBy(
|
||||
$request->input('orderBy', 'created_at'),
|
||||
$request->input('orderDir', 'desc')
|
||||
|
@ -96,13 +96,16 @@ class Link extends Model
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $userId
|
||||
* @param Builder $query
|
||||
* @param int|null $user_id
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeByUser(Builder $query, int $userId): Builder
|
||||
public function scopeByUser(Builder $query, int $user_id = null): Builder
|
||||
{
|
||||
return $query->where('user_id', $userId);
|
||||
if(is_null($user_id) && auth()->check()) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,12 +68,15 @@ class LinkList extends Model
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $user_id
|
||||
* @param Builder $query
|
||||
* @param int|null $user_id
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeByUser(Builder $query, int $user_id): Builder
|
||||
public function scopeByUser(Builder $query, int $user_id = null): Builder
|
||||
{
|
||||
if(is_null($user_id) && auth()->check()) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
@ -150,7 +153,7 @@ class LinkList extends Model
|
||||
*/
|
||||
public static function getAllForCurrentUser()
|
||||
{
|
||||
return self::byUser(auth()->id())
|
||||
return self::byUser()
|
||||
->orderBy('name')
|
||||
->get();
|
||||
}
|
||||
|
@ -54,12 +54,15 @@ class Note extends Model
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $user_id
|
||||
* @param Builder $query
|
||||
* @param int|null $user_id
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeByUser(Builder $query, int $user_id): Builder
|
||||
public function scopeByUser(Builder $query, int $user_id = null): Builder
|
||||
{
|
||||
if(is_null($user_id) && auth()->check()) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,15 @@ class Setting extends Model
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $user_id
|
||||
* @param Builder $query
|
||||
* @param int|null $user_id
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeByUser(Builder $query, int $user_id): Builder
|
||||
public function scopeByUser(Builder $query, int $user_id = null): Builder
|
||||
{
|
||||
if(is_null($user_id) && auth()->check()) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
|
@ -65,12 +65,15 @@ class Tag extends Model
|
||||
/**
|
||||
* Scope for the user relation
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $user_id
|
||||
* @param Builder $query
|
||||
* @param int|null $user_id
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeByUser(Builder $query, int $user_id): Builder
|
||||
public function scopeByUser(Builder $query, int $user_id = null): Builder
|
||||
{
|
||||
if(is_null($user_id) && auth()->check()) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
return $query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
|
@ -23,22 +23,22 @@ class TrashRepository
|
||||
switch ($model) {
|
||||
case 'links':
|
||||
$entries = Link::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
break;
|
||||
case 'lists':
|
||||
$entries = LinkList::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
break;
|
||||
case 'tags':
|
||||
$entries = Tag::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
break;
|
||||
case 'notes':
|
||||
$entries = Note::onlyTrashed()
|
||||
->byUser(auth()->id())
|
||||
->byUser()
|
||||
->get();
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user