Completed
Push — master ( 2b0ce8...94c7b3 )
by ARCANEDEV
8s
created

Redirect::createOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php namespace Arcanedev\LaravelSeo\Models;
2
3
use Symfony\Component\HttpFoundation\Response;
4
5
/**
6
 * Class     Redirect
7
 *
8
 * @package  Arcanedev\LaravelSeo\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  int             id
12
 * @property  string          old_url
13
 * @property  string          new_url
14
 * @property  int             status
15
 * @property  \Carbon\Carbon  created_at
16
 * @property  \Carbon\Carbon  updated_at
17
 */
18
class Redirect extends AbstractModel
19
{
20
    /* -----------------------------------------------------------------
21
     |  Properties
22
     | -----------------------------------------------------------------
23
     */
24
    /**
25
     * The attributes that are mass assignable.
26
     *
27
     * @var array
28
     */
29
    protected $fillable = ['old_url', 'new_url', 'status'];
30
31
    /**
32
     * The attributes that should be cast to native types.
33
     *
34
     * @var array
35
     */
36
    protected $casts = [
37
        'status' => 'integer',
38
    ];
39
40
    /* -----------------------------------------------------------------
41
     |  Constructor
42
     | -----------------------------------------------------------------
43
     */
44
    /**
45
     * Meta constructor.
46
     *
47
     * @param  array  $attributes
48
     */
49 6
    public function __construct(array $attributes = [])
50
    {
51 6
        parent::__construct($attributes);
52
53 6
        $this->setTable(config('seo.redirects.table', 'redirects'));
54 6
    }
55
56
    /* -----------------------------------------------------------------
57
     |  Main Methods
58
     | -----------------------------------------------------------------
59
     */
60
    /**
61
     * Create a redirect url.
62
     *
63
     * @param  string  $oldUrl
64
     * @param  string  $newUrl
65
     * @param  int     $status
66
     *
67
     * @return \Arcanedev\LaravelSeo\Models\Redirect
68
     */
69 6
    public static function createOne($oldUrl, $newUrl, $status = Response::HTTP_MOVED_PERMANENTLY)
70
    {
71 6
        $redirect = new self([
72 6
            'old_url' => $oldUrl,
73 6
            'new_url' => $newUrl,
74 6
            'status'  => $status,
75 2
        ]);
76
77 6
        $redirect->save();
78
79 6
        return $redirect;
80
    }
81
}
82