菜鳥學習Laravel-admin及使用helper助手添加廣告管理

 

Laravel-admin 是一個能夠快速幫你構建後臺管理的工具,它提供的頁面組件和表單元素等功能,能幫助你使用不多的代碼就實現功能完善的後臺管理功能。php

  • 內置用戶和權限系統
  • model-grid 支持快速構建數據表格
  • model-form 支持快速構建數據表單
  • model-tree 支持快速構建樹狀數據
  • 內置 40+ 種 form 元素組件、以及支持擴展組件
  • 支持 Laravel 的多種模型關係
  • mysql、mongodb、pgsql 等多數據庫支持
  • 支持引入第三方前端庫
  • 數據庫和 artisan 命令行工具的 web 實現
  • 支持自定義圖表
  • 多種經常使用 web 組件
  • 支持本地和 oss 文件上傳

 

手冊 https://laravel-admin.org/docs/zh/installationhtml

 

 

1 安裝Laravel

composer create-project laravel/laravel projectName

2 下載laravel-admin組件

composer require encore/laravel-admin

 

 

3 安裝admin模塊

artisan admin:installphp

 

 

建一個站點 指向 \localhost\china-holdings\public目錄前端

 

配置你的數據庫mysql

配置步驟 https://www.jianshu.com/p/a5382761301alaravel

就能夠訪問了 admin adminweb

 關於上傳頭像失敗的問題

1sql

\config\admin.php 有一個上傳設置mongodb

'upload' => [

        // Disk in `config/filesystem.php`.
        'disk' => 'admin',


        // Image and file upload path under the disk above.
        'directory' => [
            'image' => 'images',
            'file'  => 'files',
        ],
    ],

2數據庫

\config\filesystems.php 裏添加一個admin配置app

'admin' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

3

並打開php_fileinfo擴展

4 運行命令 設置軟連接

php artisan storage:link

 

 

若是已經存在此文件夾 須要手動刪除一下再重試

就能看到頭像了

 

安裝腳手架helpers

laravel admin 提供了腳手架,能夠幫助咱們快速搭建後臺

 

composer require laravel-admin-ext/helpers

 

php artisan admin:import helpers

 

 添加廣告管理功能

 搭建cms

參考

https://blog.csdn.net/tang05709/article/details/80843032

https://blog.csdn.net/tang05709/article/details/80843514

腳手架(Scaffold)頁面添加一個廣告管理

表名:adverts

 

點擊提交之後自動建立了三個文件和一個表。

但其實咱們要的表結構不只是單單一個adverts_title,因此咱們把表刪掉從新建立

添加如下代碼:

 

        Schema::create('adverts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('advert_desc');
            $table->string('image');
            $table->string('url');
            $table->integer('advert_type_id');
            $table->timestamps();
        });
        Schema::create('advert_types', function (Blueprint $table) {
            $table->increments('id');
            $table->string('advert_type_name');
            $table->timestamps();
        });

而後咱們把文件名+1s

運行數據庫遷移命令

 php artisan  migrate

咱們就會看到兩個新表被建立了

而後配置菜單

而後訪問http://localhost/admin/advert

發現404錯誤。由於你尚未配置路由

\app\Admin\routes.php

添加一下代碼

   //廣告
    $router->resource('advert', 'AdvertController');
    //廣告類型
    $router->resource('advert_type', 'AdvertTypeController');

 

參考閱讀

http://www.javashuo.com/article/p-bjxnifag-t.html

https://findcat.cn/archives/831

http://www.pianshen.com/article/5674254952/

相關文章
相關標籤/搜索