laravel-admin 导航选项卡表单控制器

选项卡分配

<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Tab;

class NavController extends Controller
{
    public function index(Content $content)
    {
        $forms = [
            'head'=> NavsForm\Head::class,
        ];
        
        $content->breadcrumb(['text' => '界面', 'url' => '/navs/base']);

        return $content
            ->title('系统设置')
            ->body(Tab::forms($forms));
    }
}

选项卡表单

<?php

namespace App\Admin\Controllers\NavsForm;

use Illuminate\Support\Facades\Lang;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;
use App\Admin\Models\AdminSetting;
use Cache;

class Head extends Form
{
    public $title = '主导航';
    
    public function handle(Request $request)
    {        
        $data = $request->except('_token');
        
        foreach($data as $name=>$value){
            AdminSetting::set($name, $value);
        }

        AdminSetting::setcache();

        admin_success('', '保存成功');
        return back();
    }
    public function form()
    {
        $this->table('head_nav', __('主导航'), function ($table) {
            $table->number('order', __('排序'));
            $table->text('title', __('名称'))->rules('required');
            $table->text('url', __('链接地址'))->rules('required');
            $states = ['on'  => ['value' => '1', 'text' => '显示', 'color' => 'success'], 'off' => ['value' => '0', 'text' => '隐藏', 'color' => 'danger'],];
            $table->switch('open', __('是否显示'))->states($states)->default('on');
        });
    }
    public function data()
    {
        $menus = array_values(AdminSetting::get('head_nav') ?: []);
        array_multisort(array_column($menus, 'order'), SORT_ASC, $menus);
        return [
            'head_nav'=> $menus,
        ];
    }
}
相关文章