1
|
|
|
<?php namespace Arcanedev\LaravelSeo\Models; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelSeo\Entities\RedirectStatuses; |
4
|
|
|
use Arcanedev\LaravelSeo\Seo; |
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Redirect |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\LaravelSeo\Models |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @property int id |
14
|
|
|
* @property string old_url |
15
|
|
|
* @property string new_url |
16
|
|
|
* @property int status |
17
|
|
|
* @property string status_name |
18
|
|
|
* @property \Carbon\Carbon created_at |
19
|
|
|
* @property \Carbon\Carbon updated_at |
20
|
|
|
*/ |
21
|
|
|
class Redirect extends AbstractModel |
22
|
|
|
{ |
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Properties |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
/** |
28
|
|
|
* The attributes that are mass assignable. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $fillable = ['old_url', 'new_url', 'status']; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The attributes that should be cast to native types. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $casts = [ |
40
|
|
|
'status' => 'integer', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/* ----------------------------------------------------------------- |
44
|
|
|
| Constructor |
45
|
|
|
| ----------------------------------------------------------------- |
46
|
|
|
*/ |
47
|
|
|
/** |
48
|
|
|
* Meta constructor. |
49
|
|
|
* |
50
|
|
|
* @param array $attributes |
51
|
|
|
*/ |
52
|
6 |
|
public function __construct(array $attributes = []) |
53
|
|
|
{ |
54
|
6 |
|
parent::__construct($attributes); |
55
|
|
|
|
56
|
6 |
|
$this->setTable(Seo::getConfig('redirects.table', 'redirects')); |
57
|
6 |
|
} |
58
|
|
|
|
59
|
|
|
/* ----------------------------------------------------------------- |
60
|
|
|
| Getters & Setters |
61
|
|
|
| ----------------------------------------------------------------- |
62
|
|
|
*/ |
63
|
|
|
/** |
64
|
|
|
* Get the `status_name` attribute. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
3 |
|
public function getStatusNameAttribute() |
69
|
|
|
{ |
70
|
3 |
|
return RedirectStatuses::get($this->status); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/* ----------------------------------------------------------------- |
74
|
|
|
| Main Methods |
75
|
|
|
| ----------------------------------------------------------------- |
76
|
|
|
*/ |
77
|
|
|
/** |
78
|
|
|
* Create a redirect url. |
79
|
|
|
* |
80
|
|
|
* @param string $oldUrl |
81
|
|
|
* @param string $newUrl |
82
|
|
|
* @param int $status |
83
|
|
|
* |
84
|
|
|
* @return \Arcanedev\LaravelSeo\Models\Redirect |
85
|
|
|
*/ |
86
|
6 |
|
public static function createOne($oldUrl, $newUrl, $status = Response::HTTP_MOVED_PERMANENTLY) |
87
|
|
|
{ |
88
|
6 |
|
$redirect = new self([ |
89
|
6 |
|
'old_url' => $oldUrl, |
90
|
6 |
|
'new_url' => $newUrl, |
91
|
6 |
|
'status' => $status, |
92
|
2 |
|
]); |
93
|
|
|
|
94
|
6 |
|
$redirect->save(); |
95
|
|
|
|
96
|
6 |
|
return $redirect; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|