Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Yashvant Singh
/
laravel--
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Alexey Mezenin
2021-11-06 08:09:37 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fca148cd8a006f6a6796c119881f7943896c0407
fca148cd
1 parent
d51e6a2e
Used local scope
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
app/Models/Article.php
database/database.sqlite
app/Models/Article.php
View file @
fca148c
...
...
@@ -43,20 +43,21 @@ class Article extends Model
public
function
getFiltered
(
array
$filters
)
:
Collection
{
return
$this
->
when
(
array_key_exists
(
'tag'
,
$filters
),
function
(
$q
)
use
(
$filters
)
{
$q
->
whereRelation
(
'tags'
,
'name'
,
$filters
[
'tag'
]);
})
->
when
(
array_key_exists
(
'author'
,
$filters
),
function
(
$q
)
use
(
$filters
)
{
$q
->
whereRelation
(
'user'
,
'username'
,
$filters
[
'author'
]);
})
->
when
(
array_key_exists
(
'favorited'
,
$filters
),
function
(
$q
)
use
(
$filters
)
{
$q
->
whereRelation
(
'users'
,
'username'
,
$filters
[
'favorited'
]);
})
->
when
(
array_key_exists
(
'offset'
,
$filters
),
function
(
$q
)
use
(
$filters
)
{
$q
->
offset
(
$filters
[
'offset'
])
->
limit
(
$filters
[
'limit'
]);
})
->
with
(
'user'
,
'users'
,
'tags'
,
'user.followers'
)
->
get
();
return
$this
->
filter
(
$filters
,
'tag'
,
'tags'
,
'name'
)
->
filter
(
$filters
,
'author'
,
'user'
,
'username'
)
->
filter
(
$filters
,
'favorited'
,
'users'
,
'username'
)
->
when
(
array_key_exists
(
'offset'
,
$filters
),
function
(
$q
)
use
(
$filters
)
{
$q
->
offset
(
$filters
[
'offset'
])
->
limit
(
$filters
[
'limit'
]);
})
->
with
(
'user'
,
'users'
,
'tags'
,
'user.followers'
)
->
get
();
}
public
function
scopeFilter
(
$query
,
array
$filters
,
string
$key
,
string
$relation
,
string
$column
)
{
return
$query
->
when
(
array_key_exists
(
$key
,
$filters
),
function
(
$q
)
use
(
$filters
,
$relation
,
$column
,
$key
)
{
$q
->
whereRelation
(
$relation
,
$column
,
$filters
[
$key
]);
});
}
public
function
setTitleAttribute
(
string
$title
)
:
void
...
...
database/database.sqlite
View file @
fca148c
No preview for this file type
Please
register
or
login
to post a comment