Skip to content

Instantly share code, notes, and snippets.

@akkey247
Last active May 3, 2023 08:01
Show Gist options
  • Save akkey247/0a472ed0482c7adfaa261e7d34c7ced8 to your computer and use it in GitHub Desktop.
Save akkey247/0a472ed0482c7adfaa261e7d34c7ced8 to your computer and use it in GitHub Desktop.

ルーティング・コントローラー・ビュー名

つまり、ルーティングもビューも同じ名前で指定できるようにする。
例えば、 admin.dashboard.index ならルーティングはその名前になるようにし、ビューは admin/dashboard/index.blade.php というパスにおくことで admin.dashboard.index で指定できるようにする。
コントローラーは、 index の部分は関数名になるので、 Admin/DashboardController.php とする。
その方がビューとルーティングの指定で混乱せずに済む。

ルーティング名

なるべくグループに名前をつけていくことで、プレフィックスを省略できるようにする。
index 画面は名前で省略せず xxxxx.index と書く。

Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('login', [AdminAuthLoginController::class, 'create'])->name('login');

    Route::middleware('auth:admin')->group(function () {
        Route::get('dashboard', [AdminDashboardController::class, 'index'])->name('dashboard.index');
        Route::get('profile', [AdminProfileController::class, 'index'])->name('profile.index');

コントローラー名

画面の階層に合わせてディレクトリを切る。

ビュー名

画面の階層に合わせてディレクトリを切る。
index のみの画面でもディレクトリを切って、 index.blade.php とする。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment