3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravelで管理サイトを構築する方法

Last updated at Posted at 2017-12-03

開発環境

  • Laravel5.5
  • Vagrant(Homestead)
  • Windows
  • bootstrap3

目的

  • Laravelで管理ページを構築する方法の備忘録です

作業フロー

  1. デザインのテンプレートをダウンロードします

  2. ダウンロードしてきたZipファイルを展開し、publicフォルダ内にコピペします

    • css、js、fontを移動します
  3. Resources/viewsフォルダ内にAdminというディレクトリを作成し、bladeファイルを新規で作成します

    • 新規作成したブレードファイル内に1でDLしてきた「TEMPLATE.html」のHTMLを貼り付けます
    • jsやcssのパス指定を「{{ asset('css/font-awesome.min.css') }}」のようにassetヘルパー関数を使う形に修正します
  4. 管理ページ専用のルートを作成するために、routesフォルダ内にadmin.phpファイルを新規で作成します

  5. 管理ページ専用のControllerを作成するために、Controllersフォルダ内にAdminというフォルダを新規で作成します

  6. 管理ページ専用のミドルウェアグループを作成するために、Kernel.php内の$middlewareGroups配列にadminを追加します

  7. 管理ページ専用のURLが機能するために、RouteServiceProvider.php内にmapAdminRoutesメソッドを追加します

  8. 管理ページ用のController、Bladeファイルを作成し、適時ルートも追加します

参考ソースコード

  • routes/admin.php

Route::get('users/','UserManagerController@index');
  • Providers/RouteServiceProvider.php
/**
 * アプリケーションの"admin"ルート定義
 *
 * 通常、これらのルートはステートレス
 *
 * @return void
 */
protected function mapAdminRoutes()
{
    Route::prefix('admin')
         ->middleware('admin')
         ->namespace($this->namespace . '\Admin')
         ->group(base_path('routes/admin.php'));
}
  • Controllers/Admin/UserManagerController
/**
 * Class UserManagerController
 *
 * @package App\Http\Controllers\Admin
 */
class UserManagerController extends Controller
{
    /**
     * ユーザー情報ページ(トップページ)
     *
     * @param Request $request
     * @return View
     */
    public function index(Request $request)
    {
        return view('Admin.Users.index');
    }
}

参考

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?