laravel-admin1.6版本的使用技巧以及遇到的那些坑

当你看到这篇文章的时候必定对laravel-admin有所了解,下面的用法将让你减小学习成本

excel自定义导出功能见:blog.csdn.net/qq175023117…php

若是你使用的是laravel-admin1.5.*版本点击跳转:juejin.im/post/5d0c39…html

报错:Disk [admin] not configured, please add a disk config in `config/filesystems.php`请点击连接找解决方案:blog.csdn.net/qq175023117…laravel

遇到报错:Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes请点击连接找解决方案:blog.csdn.net/qq175023117…git

如需重写内置视图以及设置语言:juejin.im/post/5d0c3c…github

本身写的办公用品管理系统 可查看源码 github.com/WXiangQian/… bootstrap

感受不错的话请点击右上角 star 谢谢支持bash

laravel-admin 手册地址:laravel-admin.org/docs/zhapp

laravel-admin demo地址 打开demo.laravel-admin.org/auth/login,用帐号密码admin/admin登录布局

laravel-admin 安装地址:laravel-admin.org/docs/zh/ins…post

model-show支持显示数据详情

1.5版本不少方法一样也适用于1.6版本中,若是本文没提到的使用技巧可直接跳转1.5版本的文章查看

这个命令用来建立一个admin用户,用交互式的方式填写用户名和密码、而且选择角色以后,会建立一个可登录的用户

php artisan admin:create-user

 Please enter a username to login: // 用户名
 > test
 Please enter a password to login: // 密码
 >
 Please enter a name to display: // 名称
 > name
 Please choose a role for the user: // 选择角色
  [0] Administrator
 > 0
User [name] created successfully.复制代码

给指定用户重置密码,根据命令的提示来操做

php artisan admin:reset-password


Please enter a username who needs to reset his password:  // 输入重置哪一个用户名的密码
 > test
t?[K?7est?8e?[K?7st?8s?[K?7t?8t?[K?7?8
 Please enter a password: // 新密码
 >
 Please confirm the password: // 确认新密码
 >
User password reset successfully.复制代码
自定义头部导航条  从版本`1.5.6`开始,能够在顶部导航条上添加html元素了, 
 打开`app/Admin/bootstrap.php`:
`left`和`right`方法分别用来在头部的左右两边添加内容,
方法参数能够是任何能够渲染的对象(实现了`Htmlable`、`Renderable`接口或者包含`__toString()`方法的对象)或字符串复制代码
use Encore\Admin\Facades\Admin;
Admin::navbar(function (\Encore\Admin\Widgets\Navbar $navbar) {
    $navbar->left('html...');
    $navbar->right('html...');
});复制代码
左侧添加示例  举个例子,好比在左边添加一个搜索条,
先建立一个blade视图`resources/views/search-bar.blade.php`:复制代码
<style>
.search-form {
    width: 250px;
    margin: 10px 0 0 20px;
    border-radius: 3px;
    float: left;
}
.search-form input[type="text"] {
    color: #666;
    border: 0;
}
.search-form .btn {
    color: #999;
    background-color: #fff;
    border: 0;
}
</style>

<form action="/admin/posts" method="get" class="search-form" pjax-container>
    <div class="input-group input-group-sm ">
        <input type="text" name="title" class="form-control" placeholder="Search...">
        <span class="input-group-btn">
            <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i></button>
          </span>
    </div>
</form>

//而后加入头部导航条:
$navbar->left(view('search-bar'));
复制代码
model-grid能够经过下面的方式关闭修改、查看、删除按钮:复制代码
$grid->actions(function ($actions) {
    // $actions->disableDelete();
    // $actions->disableEdit();
    //禁用显示详情按钮
    $actions->disableView();
});复制代码

上传头像不显示问题

config--->admin.php
将'disk'=>'admin' 修改为 'disk' => 'public'
在所属项目执行 php artisan storage:link 刷新页面,从新上传,就能正常显示上传的头像。复制代码

修改 laravel-admin form布局($form->row)

$form->row(function ($row) use ($form)
{
      $row->width(4)->text('id', 'id')->rules('required');
      $row->width(4)->text('name', 'name')->rules('required');
      $row->width(4)->text('value', 'value')->rules('required');

},  $form); 复制代码

Grid过滤器支持多列布局

若是过滤器太多,会把页面拉的很长,将会很影响页面的观感,这个版本将支持过滤器的多列布局, 好比6个过滤器分两列显示

$filter->column(1/2, function ($filter) {
    $filter->like('title');
    $filter->between('rate');
});

$filter->column(1/2, function ($filter) {
    $filter->equal('created_at')->datetime();
    $filter->between('updated_at')->datetime();
    $filter->equal('released')->radio([
        1 => 'YES',
        0 => 'NO',
    ]);
});复制代码

默认会有一个主键字段的过滤器放在第一列,全部左右各三个过滤器一共6个过滤器

column方法的第一个参数设置列宽度,能够设置为比例1/20.5,或者bootstrap的栅格列宽度好比6,若是三列的话能够设置为1/3或者4

文章不断更新中~~~感谢支持

相关文章
相关标签/搜索