ArticleController::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Repositories\Criteria\Like;
6
use App\Repositories\Criteria\Where;
7
use App\Repositories\PostRepository;
8
9
class ArticleController extends DataController
10
{
11
    public function index()
12
    {
13
        if (request()->filled('id')) {
14
            $this->repository->pushCriteria(new Where('id', request('id')));
15
        }
16
        if (request()->filled('title')) {
17
            $this->repository->pushCriteria(new Like('title', request('title')));
18
        }
19
        if (request()->filled('status')) {
20
            $this->repository->pushCriteria(new Where('status', request('status')));
21
        }
22
23
        return parent::index();
24
    }
25
26
    public function store()
27
    {
28
        $attrs = request()->all();
29
        $attrs['user_id'] = request('user_id', request()->user()->id);
30
31
        return $this->repository->create($attrs);
32
    }
33
34
    protected function getRepository()
35
    {
36
        return PostRepository::class;
37
    }
38
}
39