0 レビュー
135 回答
php-LaravelでURIをプレフィックスせずにルート名をプレフィックスする
2つの名前空間'Front'
と'Admin'
があります。 'Admin' 名前空間の場合、すべてのパスの前に admin.conrtoller.action を付けてもかまいませんが、'Front'<の場合は/code>プレフィックス付きのURIなしでプレフィックス付きのルート名を使用したい。
Route :: group(array('namespace' => 'Front')、function()
{{
Route :: resource('franchising'、'FranchisingController'、array('only' => array('index')));
});
これにより、 franchising.index
ルート名とget 'franchising'
URIが生成されます。このグループ内のすべてのリソースを作成して、front。franchising.indexのようなルート名を生成する方法。ただし、現在のURIは変更せずに残します(つまり、接頭辞として front/を付けないでください)。 )。
Laravel4.2を使用しています。
2022-04-17
わからない
0
レビュー
答え : 解決策: プレフィックスをnoneに設定するだけです:
Route::group(array('namespace' => 'Front', 'prefix'=>''), function()
更新:
Routeクラスを拡張して、この1つの関数をオーバーライドできるはずです:
class MyRoute extends \Laravel\Routing\Route {
/**
* Add a prefix to the route URI.
*
* @param string $prefix
* @return \Illuminate\Routing\Route
*/
public function prefix($prefix)
{
$this->uri = trim($this->uri, '/'); // removed the prefix from this line
return $this;
}
}
次に、通常のルートの代わりに使用します:
MyRoute::group(array('namespace' => 'Front'), function()
更新:
拡張機能が必要になる場合があります
use Illuminate\Support\Facades\Route;
class MyRoute extends Route {
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : 解決策: ルートprefixは、主にパスをprefixするためのものです。ルート名もprefixするという事実は、 Route::resource()
を使用する場合の追加の動作にすぎません。
編集
Laravelでprefixルートグループパラメータを使用して、実際のprefixをそのまま使用することは絶対に不可能です。
Route::resource()
とRoute::controller()は、実際の使用例の一部であり、それらが適合する場合のショートカットにすぎません。それらは間違いなくすべてに適合するツールではありません。ルートをさらに制御する必要がある場合は、 Route::get 、 Route::post
などを使用してルートを手動で指定することをお勧めします。
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : 解決策: 少なくともLaravel5.4を使用している新規参入者に最新の回答を提供するために、いつ導入されたかは正確にはわかりませんが、配列オプション{-を渡すことができます。 code-1}
ルートを定義してURIや名前空間に影響を与えずにすべてのルート名にプレフィックスを付ける場合。
たとえば、laravelの新規インストールから始めて、 {-code-2}
モデルを作成します。
php artisan make:model {-code-2}
これには、 {-code-4}
コントローラーと{-code-5}
コントローラーの両方からアクセスする必要があります。
php artisan make:controller --resource --model ='{-code-2}''{-code-4} \ {-code-2} Controller'
php artisan make:controller --resource --model ='{-code-2}''{-code-5} \ {-code-2} Controller'
これにより、次のファイルが作成されます。
app /
├──..。
├──{-code-2}.php
├──Http
│├──コントローラー
││├──{-コード-5}
│││└──{-code-2}Controller.php
││├──..。
││└──{-コード-4}
││└──{-code-2}Controller.php
│└──..。
└──..。
オプションを使用してリソースルートを作成し、ルート名のプレフィックスを定義します。
Route :: resource(
「フランチャイズ」、
'{-code-4} \ {-code-2} Controller'、
[=>'フロント']
);
Route :: resource(
「管理者/フランチャイズ」、
'{-code-5} \ {-code-2} Controller'、
[ =>'admin']
);
職人がいるすべてのルートを表示できます:
{-code-10}
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
|方法| URI |名前|アクション|
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
| GET | HEAD |管理者/フランチャイズ| admin.franchising.index | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ index |
| POST |管理者/フランチャイズ| admin.franchising.store | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ store |
| GET | HEAD |管理者/フランチャイズ/作成| admin.franchising.create | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ create |
| GET | HEAD | admin / franchising / {franchising} | admin.franchising.show | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ show |
| PUT | PATCH | admin / franchising / {franchising} | admin.franchising.update | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ update |
|削除| admin / franchising / {franchising} | admin.franchising.destroy | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ destroy |
| GET | HEAD |管理者/フランチャイズ/{フランチャイズ}/編集| admin.franchising.edit | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ edit |
| GET | HEAD |フランチャイズ| front.franchising.index | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ index |
| POST |フランチャイズ| front.franchising.store | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ store |
| GET | HEAD |フランチャイズ/作成| front.franchising.create | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ create |
| GET | HEAD |フランチャイズ/{フランチャイズ}| front.franchising.show | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ show |
| PUT | PATCH |フランチャイズ/{フランチャイズ}| front.franchising.update | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ update |
|削除|フランチャイズ/{フランチャイズ}| front.franchising.destroy | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ destroy |
| GET | HEAD |フランチャイズ/{フランチャイズ}/編集| front.franchising.edit | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ edit |
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
特定のユースケースでは、フロントコントローラーで1つのルートしか使用していないことに気付きました。したがって、この一般的なソリューションの代わりに、実際にはその1つのルートを定義する方がよい場合があります。
Route :: name('front.franchising.index')
-> get('franchising'、'{-code-4} \ {-code-2} Controller @ index');
Route :: resource(
「管理者/フランチャイズ」、
'{-code-5} \ {-code-2} Controller'、
[ =>'admin']
);
これらのルートを生成するもの:
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
|方法| URI |名前|アクション|
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
| GET | HEAD |管理者/フランチャイズ| admin.franchising.index | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ index |
| POST |管理者/フランチャイズ| admin.franchising.store | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ store |
| GET | HEAD |管理者/フランチャイズ/作成| admin.franchising.create | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ create |
| GET | HEAD | admin / franchising / {franchising} | admin.franchising.show | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ show |
| PUT | PATCH | admin / franchising / {franchising} | admin.franchising.update | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ update |
|削除| admin / franchising / {franchising} | admin.franchising.destroy | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ destroy |
| GET | HEAD |管理者/フランチャイズ/{フランチャイズ}/編集| admin.franchising.edit | App \ Http \ Controllers \ {-code-5} \ {-code-2} Controller @ edit |
| GET | HEAD |フランチャイズ| front.franchising.index | App \ Http \ Controllers \ {-code-4} \ {-code-2} Controller @ index |
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
|方法| URI |名前|アクション|
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
| GET | HEAD |管理者/フランチャイズ| admin.franchising.index | App \ Http \ Controllers \ Admin \ FranchisingController @ index |
| POST |管理者/フランチャイズ| admin.franchising.store | App \ Http \ Controllers \ Admin \ FranchisingController @ store |
| GET | HEAD |管理者/フランチャイズ/作成| admin.franchising.create | App \ Http \ Controllers \ Admin \ FranchisingController @ create |
| GET | HEAD | admin / franchising / {franchising} | admin.franchising.show | App \ Http \ Controllers \ Admin \ FranchisingController @ show |
| PUT | PATCH | admin / franchising / {franchising} | admin.franchising.update | App \ Http \ Controllers \ Admin \ FranchisingController @ update |
|削除| admin / franchising / {franchising} | admin.franchising.destroy | App \ Http \ Controllers \ Admin \ FranchisingController @ destroy |
| GET | HEAD |管理者/フランチャイズ/{フランチャイズ}/編集| admin.franchising.edit | App \ Http \ Controllers \ Admin \ FranchisingController @ edit |
| GET | HEAD |フランチャイズ| front.franchising.index | App \ Http \ Controllers \ Front \ FranchisingController @ index |
| POST |フランチャイズ| front.franchising.store | App \ Http \ Controllers \ Front \ FranchisingController @ store |
| GET | HEAD |フランチャイズ/作成| front.franchising.create | App \ Http \ Controllers \ Front \ FranchisingController @ create |
| GET | HEAD |フランチャイズ/{フランチャイズ}| front.franchising.show | App \ Http \ Controllers \ Front \ FranchisingController @ show |
| PUT | PATCH |フランチャイズ/{フランチャイズ}| front.franchising.update | App \ Http \ Controllers \ Front \ FranchisingController @ update |
|削除|フランチャイズ/{フランチャイズ}| front.franchising.destroy | App \ Http \ Controllers \ Front \ FranchisingController @ destroy |
| GET | HEAD |フランチャイズ/{フランチャイズ}/編集| front.franchising.edit | App \ Http \ Controllers \ Front \ FranchisingController @ edit |
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- + ||| Route :: name('front.franchising.index')
-> get('franchising'、'Front \ FranchisingController @ index');
Route :: resource(
「管理者/フランチャイズ」、
'Admin \ FranchisingController'、
['as' =>'admin']
); ||| +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
|方法| URI |名前|アクション|
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
| GET | HEAD |管理者/フランチャイズ| admin.franchising.index | App \ Http \ Controllers \ Admin \ FranchisingController @ index |
| POST |管理者/フランチャイズ| admin.franchising.store | App \ Http \ Controllers \ Admin \ FranchisingController @ store |
| GET | HEAD |管理者/フランチャイズ/作成| admin.franchising.create | App \ Http \ Controllers \ Admin \ FranchisingController @ create |
| GET | HEAD | admin / franchising / {franchising} | admin.franchising.show | App \ Http \ Controllers \ Admin \ FranchisingController @ show |
| PUT | PATCH | admin / franchising / {franchising} | admin.franchising.update | App \ Http \ Controllers \ Admin \ FranchisingController @ update |
|削除| admin / franchising / {franchising} | admin.franchising.destroy | App \ Http \ Controllers \ Admin \ FranchisingController @ destroy |
| GET | HEAD |管理者/フランチャイズ/{フランチャイズ}/編集| admin.franchising.edit | App \ Http \ Controllers \ Admin \ FranchisingController @ edit |
| GET | HEAD |フランチャイズ| front.franchising.index | App \ Http \ Controllers \ Front \ FranchisingController @ index |
+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -+
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : ------- +
答えへのリンク
2022-04-17
わからない
0
レビュー
答え : -------- +
答えへのリンク
2022-04-17
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。