====== 27 Laravel Voyager ====== $ laravel new $ composer require tcg/voyager ===== app.phpのProviderに追加 ===== 'providers' => [ ・ ・ TCG\Voyager\VoyagerServiceProvider::class, ===== インストール ===== $ php artisan voyager:install --with-dummy ===== Voyager コントローラーカスタマイズ ===== 今回Songsモデルを作成している事を前提に説明 $ php artisan make:model Songs ==== 1.BREADを作成 ==== 作成したSongsモデルから、BREADを作成する {{:11_php:02_framework:01_laravel:voyager.png?400|}} ==== 2.View OverRide ==== 今回の場合、slug-naeがsongsになります。 resources/views/vendor/voyager/[slug-name] 以下にbrose.blade.phpとedit-add.blade.phpを置けばオーバライドされる。 デフォルトのビューをコピーして利用 cp vendor/tcg/voyager/resources/views/bread/browse.blade.php resources/views/vendor/voyager/songs/ cp vendor/tcg/voyager/resources/views/bread/edit-add.blade.php resources/views/vendor/voyager/songs/ [[https://voyager.readme.io/docs/overriding-views]] === 他のViewもvenderから出す場合 === vendor/tcg/voyager/resources/views/を全部コピーしておく $ rsync -av vendor/tcg/voyager/resources/views/ resources/views/vendor/voyager/ === langも出しておく === $ rsync -av vendor/tcg/voyager/publishable/lang/ja/ resources/lang/vendor/voyager/ja/ ==== 3.コントローラーの参照先変更 ==== config/voyager.phpを修正 'controllers' => [ - 'namespace' => 'TCG\\Voyager\\Http\\Controllers', + //'namespace' => 'TCG\\Voyager\\Http\\Controllers', + 'namespace' => 'App\\Http\\Controllers\\Voyager', ], voyager:controllersを実行 $ php artisan voyager:controllers $ ll app/Http/Controllers/Voyager/ total 44 -rw-r--r-- 1 matsui users 207 Apr 3 10:40 VoyagerAuthController.php -rw-r--r-- 1 matsui users 207 Apr 3 10:40 VoyagerBaseController.php -rw-r--r-- 1 matsui users 211 Apr 3 10:40 VoyagerBreadController.php -rw-r--r-- 1 matsui users 219 Apr 3 10:40 VoyagerCompassController.php -rw-r--r-- 1 matsui users 191 Apr 3 10:40 VoyagerController.php -rw-r--r-- 1 matsui users 223 Apr 3 10:40 VoyagerDatabaseController.php -rw-r--r-- 1 matsui users 211 Apr 3 10:40 VoyagerMediaController.php -rw-r--r-- 1 matsui users 207 Apr 3 10:40 VoyagerMenuController.php -rw-r--r-- 1 matsui users 207 Apr 3 10:40 VoyagerRoleController.php -rw-r--r-- 1 matsui users 223 Apr 3 10:40 VoyagerSettingsController.php -rw-r--r-- 1 matsui users 207 Apr 3 10:40 VoyagerUserController.php ==== 4.コントローラーをコピーしてくる ==== ベースを元にコピーしてきて、namespaceと参照先を変更してやればよい。 # cp vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php app/Http/Controllers/Voyager/SongsController.php $ diff -u vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php app/Http/Controllers/Voyager/SongsController.php --- vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php 2019-03-10 03:54:39.000000000 +0900 +++ app/Http/Controllers/Voyager/SongsController.php 2019-04-03 12:32:52.553751402 +0900 @@ -1,6 +1,6 @@ ==== 5.RouteのOverride ==== Route::group(['prefix' => 'admin'], function () { Voyager::routes(); Route::get('songs','Voyager\SongsController@index')->name('voyager.songs.index')->middleware('admin.user'); Route::post('songs','Voyager\SongsController@index')->name('voyager.songs.index')->middleware('admin.user'); }); {{tag>Laravel Voyager}}