回答編集履歴
2
追記
test
CHANGED
@@ -142,6 +142,10 @@
|
|
142
142
|
|
143
143
|
|
144
144
|
|
145
|
+
[https://readouble.com/laravel/5.8/ja/middleware.html](https://readouble.com/laravel/5.8/ja/middleware.html)
|
146
|
+
|
147
|
+
|
148
|
+
|
145
149
|
```php
|
146
150
|
|
147
151
|
Route::middleware(['is_smartphone'])->group(function () {
|
1
追記
test
CHANGED
@@ -4,7 +4,141 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
```bash
|
8
|
+
|
9
|
+
composer require jenssegers/agent
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
|
7
|
-
middleware で判定部分を実装し
|
15
|
+
middleware で判定部分を実装します。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```bash
|
20
|
+
|
21
|
+
php artisan make:middleware CheckSmartPhone
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
上記のコマンドで以下のファイルが生成される
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```php
|
32
|
+
|
33
|
+
<?php
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
/**
|
38
|
+
|
39
|
+
* app/Http/Middleware/CheckSmartPhone.php
|
40
|
+
|
41
|
+
*/
|
42
|
+
|
43
|
+
namespace App\Http\Middleware;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
use Closure;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
class CheckSmartPhone
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
/**
|
56
|
+
|
57
|
+
* Handle an incoming request.
|
58
|
+
|
59
|
+
*
|
60
|
+
|
61
|
+
* @param \Illuminate\Http\Request $request
|
62
|
+
|
63
|
+
* @param \Closure $next
|
64
|
+
|
65
|
+
* @return mixed
|
66
|
+
|
67
|
+
*/
|
68
|
+
|
69
|
+
public function handle($request, Closure $next)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
return $next($request);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
これに、以下のように実装して
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```php
|
88
|
+
|
89
|
+
<?php
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
namespace App\Http\Middleware;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
use Closure;
|
98
|
+
|
99
|
+
use Jenssegers\Agent\Agent;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
class CheckSmartPhone
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
/**
|
108
|
+
|
109
|
+
* Handle an incoming request.
|
110
|
+
|
111
|
+
*
|
112
|
+
|
113
|
+
* @param \Illuminate\Http\Request $request
|
114
|
+
|
115
|
+
* @param \Closure $next
|
116
|
+
|
117
|
+
* @return mixed
|
118
|
+
|
119
|
+
*/
|
120
|
+
|
121
|
+
public function handle($request, Closure $next)
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
if ((new Agent())->isMobile()) {
|
126
|
+
|
127
|
+
return redirect('non-smart-phone', 403);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
return $next($request);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
`app/Http/Kernel.php` へミドルウェアの短縮キーを登録した上で、
|
8
142
|
|
9
143
|
|
10
144
|
|
@@ -12,7 +146,7 @@
|
|
12
146
|
|
13
147
|
Route::middleware(['is_smartphone'])->group(function () {
|
14
148
|
|
15
|
-
//
|
149
|
+
// スマホのときに表示するルートを記述
|
16
150
|
|
17
151
|
}
|
18
152
|
|