回答編集履歴
3
汎用的なものに修正
test
CHANGED
@@ -8,27 +8,43 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
ルーティング
|
11
|
+
ルーティング(汎用的なものに修正)
|
12
12
|
|
13
13
|
```PHP
|
14
14
|
|
15
|
-
|
15
|
+
// その他ルーティング
|
16
16
|
|
17
|
-
|
17
|
+
Route::any('a/b/c', 'AbcsController@abc');
|
18
18
|
|
19
|
-
$paths[0] = \Doctrine\Common\Inflector\Inflector::classify($paths[0]);
|
20
19
|
|
21
|
-
$paths[1] = \Doctrine\Common\Inflector\Inflector::classify($paths[1]);
|
22
20
|
|
23
|
-
|
21
|
+
// [ 規定 ]
|
24
22
|
|
25
|
-
|
23
|
+
// https://ドメイン/ディレクトリ/コントローラファイル名/アクション名/id/
|
26
24
|
|
27
|
-
|
25
|
+
$paths = explode('/', Request::path());
|
28
26
|
|
29
|
-
|
27
|
+
if (!empty($paths) && count($paths) >= 3) {
|
30
28
|
|
29
|
+
// 規定にマッチするが、別にルーティングをしたい場合
|
30
|
+
|
31
|
+
// 規定と同じURLのものがある場合は、先に書いた方が優先して表示される
|
32
|
+
|
33
|
+
Route::any('aa/bb/cc', 'FugasController@aaa');
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// 規定通りにルーティングをする場合
|
38
|
+
|
39
|
+
$paths[0] = \Doctrine\Common\Inflector\Inflector::classify($paths[0]);
|
40
|
+
|
41
|
+
$paths[1] = \Doctrine\Common\Inflector\Inflector::classify($paths[1]);
|
42
|
+
|
43
|
+
Route::group(['namespace' => $paths[0]], function () use ($paths) {
|
44
|
+
|
45
|
+
Route::any('{directory}/{controller}/{action}/{id?}/', $paths[1].'Controller@'.$paths[2]);
|
46
|
+
|
31
|
-
|
47
|
+
});
|
32
48
|
|
33
49
|
}
|
34
50
|
|
2
ネームスペースを例と統一
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
```PHP
|
42
42
|
|
43
|
-
namespace App\Http\Controllers\
|
43
|
+
namespace App\Http\Controllers\Hoge;
|
44
44
|
|
45
45
|
|
46
46
|
|
1
ディレクトリーをコントローラーの階層に変更
test
CHANGED
@@ -8,15 +8,23 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
ルーティング
|
12
|
+
|
11
13
|
```PHP
|
12
14
|
|
13
15
|
try {
|
14
16
|
|
15
17
|
$paths = explode('/', Request::path());
|
16
18
|
|
19
|
+
$paths[0] = \Doctrine\Common\Inflector\Inflector::classify($paths[0]);
|
20
|
+
|
17
21
|
$paths[1] = \Doctrine\Common\Inflector\Inflector::classify($paths[1]);
|
18
22
|
|
23
|
+
Route::group(['namespace' => $paths[0]], function () use ($paths) {
|
24
|
+
|
19
|
-
Route::any('{directory}/{controller}/{action}/{id?}/', $paths[1].'Controller@'.$paths[2]);
|
25
|
+
Route::any('{directory}/{controller}/{action}/{id?}/', $paths[1].'Controller@'.$paths[2]);
|
26
|
+
|
27
|
+
});
|
20
28
|
|
21
29
|
} catch (Exception $e) {
|
22
30
|
|
@@ -28,13 +36,41 @@
|
|
28
36
|
|
29
37
|
|
30
38
|
|
39
|
+
コントローラーの例
|
40
|
+
|
41
|
+
```PHP
|
42
|
+
|
43
|
+
namespace App\Http\Controllers\Abc;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class HogesController extends \App\Http\Controllers\Controller
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
public function show($directory, $controller, $action, $id=null)
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
dd([$directory, $controller, $action, $id]);
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
31
67
|
例:
|
32
68
|
|
33
69
|
https://example.com/hoge/hoges/show/123/
|
34
70
|
|
35
71
|
(ドメイン:example.comを利用)
|
36
72
|
|
37
|
-
(ディレクトリー:
|
73
|
+
(ディレクトリー:App\Http\Controllers\Hogeにコントローラーがある)
|
38
74
|
|
39
75
|
(コントローラー:HogesController)
|
40
76
|
|
@@ -44,9 +80,7 @@
|
|
44
80
|
|
45
81
|
|
46
82
|
|
47
|
-
|
48
|
-
|
49
|
-
上記コードの```\Doctrine\Common\Inflector\Inflector::classify()```は以下を使っています。
|
83
|
+
上記ルーティングのコードの```\Doctrine\Common\Inflector\Inflector::classify()```は以下を使っています。
|
50
84
|
|
51
85
|
|
52
86
|
|