Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel NovaºÍAdminLTEÌìÉúºǫ́ÖÎÀí½çÃ棿
ÔÚÏÖ´úwebÓ¦ÓóÌÐòÖУ¬ÖÎÀí½çÃæÊÇÒ»¸ö±ØÐèҪ˼Á¿µÄÖ÷Òª²¿·Ö¡£ËüÐèÒªÊÇÖ±¹Û¡¢Ò×ÓÚʹÓú͹¦Ð§¸»ºñµÄ¡£ÎªÁËʵÏÖÕâһĿµÄ£¬laravelÌṩÁËlaravel novaºÍadminlteÁ½¸ö¿ò¼Ü¡£
Laravel NovaÊÇLaravelÖеÄÒ»¸öÖÎÀíÃæ°å£¬Ëü¿ÉÒÔÔÚ¼¸·ÖÖÓÄÚΪÄúµÄLaravelÓ¦ÓóÌÐòÌìÉúÒ»¸öÖÎÀíÃæ°å¡£Laravel Nova¾ßÓÐÑŹ۵ÄUI¡¢Óû§ÖÎÀí¡¢CMSµÈ¹¦Ð§£¬Ê¹¿ª·¢Ö°Ô±Äܹ»¸ü¿ì¡¢¸üÇáËɵؽ¨ÉèÖØ´óµÄÓ¦ÓóÌÐò¡£
ÁíÒ»·½Ã棬AdminLTEÊÇÒ»¸öÃâ·ÑµÄºǫ́ÖÎÀíÄ£°å£¬Ëü»¹ÌṩÁËÒ»¸ö²»´íµÄÓû§½çÃæºÍÐëÒªµÄJavaScript¿â¡£ËüÊÇ»ùÓÚBootstrap CSS¿ò¼ÜµÄ£¬Ò²ÊÇÏìӦʽµÄ¡£Äú¿ÉÒÔÔÚÍâµØ°²ÅźÍÍйÜAdminLTE£¬´Ó¶ø»ñµÃÒ»¸ö¿ìËÙ¡¢×Ô½ç˵µÄÖÎÀí½çÃæ¡£
ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝʹÓÃLaravel NovaºÍAdminLTEÀ´ÌìÉúÒ»¸öƯÁÁµÄÖÎÀí½çÃæµÄÒªÁì¡£
°ì·¨1£º×°ÖÃLaravel Nova
ҪʹÓÃLaravel Nova½¨ÉèÒ»¸öÖÎÀíÃæ°å£¬ÄúÐèÒªÏÈ×°ÖÃLaravel Nova¡£Çëƾ֤ÒÔÏ°취Íê³É×°Öãº
ÔÚÄúµÄLaravelÓ¦ÓóÌÐòÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁî×°ÖÃNova£ºcomposer require laravel/nova.
ÐÞ¸Ä config/app.php Îļþ£¬½«ÒÔÏÂÐÐÌí¼Óµ½ providers Êý×éÖУºLaravelNovaNovaServiceProvider::class.
ΪÓû§×¢²áNovaµÄ·ÓÉ£¬·¿ª app/Providers/NovaServiceProvider.phpÎļþ£¬Ìí¼ÓÒÔÏÂÒªÁ죺
use LaravelNovaNova; protected function routes() { Nova::routes() ->withAuthenticationRoutes() ->withPasswordResetRoutes() ->register(); }
µÇ¼ºó¸´ÖÆ
°ì·¨2£º½¨ÉèNova×ÊÔ´
ÔÚLaravel NovaÖУ¬×ÊÔ´ÓÃÓÚÓëÊý¾Ý¿âÄ£×Ó¾ÙÐн»»¥¡£Òª½¨ÉèÒ»¸ö×ÊÔ´£¬ÇëÔËÐÐÒÔÏÂÏÂÁ
php artisan nova:resource {resourceName}
µÇ¼ºó¸´ÖÆ
Õ⽫ÔÚ app/Nova Ŀ¼Öн¨ÉèÒ»¸ö×ÊÔ´Àà¡£ÔÚ×ÊÔ´ÀàÖУ¬Äú¿ÉÒÔ½ç˵ÔõÑùÖÎÀíºÍչʾ×ÊÔ´Êý¾Ý¡£ÀýÈ磬ÒÔÏ´úÂë½ç˵ÔõÑùÏÔʾUser×ÊÔ´£º
namespace AppNova; use LaravelNovaResource; use LaravelNovaFieldsID; use LaravelNovaFieldsText; use LaravelNovaFieldsGravatar; class User extends Resource { /** * The model the resource corresponds to. * * @var string */ public static $model = 'App\User'; /** * Get the displayable label of the resource. * * @return string */ public static function label() { return __('Users'); } /** * Get the displayable singular label of the resource. * * @return string */ public static function singularLabel() { return __('User'); } /** * Get the fields displayed by the resource. * * @param IlluminateHttpRequest $request * @return array */ public function fields(Request $request) { return [ ID::make()->sortable(), Gravatar::make(), Text::make('Name')->sortable(), Text::make('Email')->sortable(), ]; } }
µÇ¼ºó¸´ÖÆ
°ì·¨3£º×¢²áNova×ÊÔ´
ÔÚresources/assets/js/app.jsÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
import Nova from './vendor/laravel/nova/Nova.js'; Nova.booting((Vue, router, store) => { router.addRoutes([ { name: 'nova', path: '/nova', component: require('./views/Nova'), }, ]) })
µÇ¼ºó¸´ÖÆ
Ìí¼Ó·ÓÉ£¬Ê¹Laravel¿ÉÒÔ»á¼ûNova£º
Route::get('/nova', function () { return view('nova'); });
µÇ¼ºó¸´ÖÆ
×îºó£¬½«ÒÔÏÂÄÚÈÝÌí¼Óµ½ÄúµÄwebpack.mix.jsÎļþ£º
mix.js('resources/js/app.js', 'public/js') .sass('resources/sass/app.scss', 'public/css') .sourceMaps(); if (mix.inProduction()) { mix.version(); }
µÇ¼ºó¸´ÖÆ
°ì·¨4£ºÊ¹ÓÃAdminLTEºÍNova»ìÏý
ÏÖÔÚÄúÒѾװÖÃÁËLaravel NovaºÍ½¨ÉèÁËNova×ÊÔ´¡£ÏÂÒ»²½Êǽ«AdminLTEÑùʽ±íºÍJavaScript¿âÌí¼Óµ½Nova×ÊÔ´ÖУ¬ÒԱ㽨Éè¾ßÓÐAdminLTEÑùʽµÄ×Ô½ç˵ÖÎÀíÃæ°å¡£
ÏÂÔØAdminLTE²¢½«Æä½âѹËõµ½ public Ŀ¼ÖС£ÏÂÃæÊÇÏÂÔØÁ´½Ó£ºhttps://adminlte.io/themes/dev/AdminLTE/
½¨ÉèÒ»¸öеÄÊÓͼÀ´·ºÆðÖÎÀíÃæ°å¡£Ëü½«ÏÔʾÔÚ/novaµÄ·ÓÉÖС£
»ùÓÚÄ¿½ñµÄÄ£°å£¬½¨ÉèÒ»¸önova.blade.phpÎļþ£¬²¢½«ÒÔÏÂÄÚÈݲåÈëµ½ÎļþÖУº
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compati ble" content="ie=edge"> <title>{{ config('app.name') }} - {{__('Nova')}}</title> <!-- Include AdminLTE CSS --> <link rel="stylesheet" href="/css/adminlte.css"> </head> <body class="hold-transition sidebar-mini"> <div id="app"> <nova/> </div> <!-- Include AdminLTE and jQuery JavaScript --> <script src="/js/adminlte.js"></script> <script src="{{ asset('js/app.js') }}"></script> </body> </html>
µÇ¼ºó¸´ÖÆ
ÔÚеÄÊÓͼÖУ¬½«ÒÔÏÂÄÚÈÝ°üÀ¨µ½body±êÇ©ÖУº
<div class="wrapper"> {{-- Main navigation --}} <nav class="main-header navbar navbar-expand navbar-white navbar-light"> </nav> {{-- Left side column. contains the logo and sidebar --}} <aside class="main-sidebar sidebar-dark-primary elevation-4"> </aside> {{-- Content Wrapper. Contains page content --}} <div class="content-wrapper"> <section class="content"> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> {{-- Your Nova API Resource --}} {{-- Example: @resource('users') --}} </div> </div> </div> </section> </div> {{-- Main Footer --}} <footer class="main-footer"> </footer> </div>
µÇ¼ºó¸´ÖÆ
ÔÚÄãµÄConponentsÖн¨ÉèÒ»¸öеÄVue Component²¢ÃüÃûΪNova¡£Nova ComponentÔÚ½¨ÉèʱÐèҪע²á·ÓɺÍÏà¹ØÐÅÏ¢£º
require('./bootstrap'); import Vue from 'vue'; import Nova from './Nova'; import router from './router'; import store from './store'; Vue.component('nova', Nova); const app = new Vue({ el: '#app', router, store });
µÇ¼ºó¸´ÖÆ
Ìí¼ÓÒ»¸öеķÓÉÀ´´¦Àínova·ÓÉ£¬ËüÓ¦¸ÃÖ¸Ïò¶ÔÓ¦µÄVue Component£º
import Vue from 'vue'; import Router from 'vue-router'; import Home from './components/Home'; import Nova from './Nova'; Vue.use(Router); export default new Router({ // ... { path: '/nova', name: 'nova', component: Nova, }, // ... });
µÇ¼ºó¸´ÖÆ
ÑéÖ¤NovaµÄÑùʽ±íºÍJavaScriptÊÇ·ñŲÓÃÕý³££¬Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
php artisan serve
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÄúÒѾÀֳɽ«Laravel NovaºÍAdminLTE»ìÏýʹÓ㬿ÉÒÔ×Ô½ç˵ÖÎÀíÃæ°åÁË¡£
½áÂÛ
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓÃLaravel NovaºÍAdminLTEÀ´½¨ÉèÒ»¸öƯÁÁ¡¢ÎÞаµÄÖÎÀíÃæ°å¡£ÕâЩ¹¤¾ßµÄÇ¿Ê¢×éºÏ¿ÉÒÔΪ¿ª·¢Ö°Ô±Ìṩһ¸ö¿ìËÙµÄÒªÁìÀ´½¨Éè¾ßÓÐÖØ´ó¹¦Ð§µÄÓ¦ÓóÌÐò£¬²¢×ÊÖú¿ª·¢Ö°Ô±¸ü¿ìµØʵÏÖÆäÓªÒµÐèÇó¡£Ï£Íû¶ÁÕßÄܹ»´Ó±¾ÎÄÖÐÏàʶµ½¸ü¶à¹ØÓÚLaravel¿ò¼ÜµÄÄÚÈÝ¡£
ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel NovaºÍAdminLTEÌìÉúºǫ́ÖÎÀí½çÃ棿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡