菜鸟学习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/

相关文章
相关标签/搜索