laravel-admin(自定義表單與驗證)


場景:

很多時候,由於我們業務場景比較特殊,需要自定義表單,然后框架給我提供了對應表單組建!

案列:以創建一個字段為列

1.在控制器對應的方法中調用表單組建創建表單

 public function create(Content $content)
    {
        $f = new \Encore\Admin\Widgets\Form();
        $f->action('/adminyc/area');
        $f->textarea('name', '簡介')->help('簡介');
        return $content
            ->header('Create')
            ->description('description')
            ->body($f);
    }

 

2.對應的保存函數中進行數據處理與驗證

    public function store(Request $request)
    {
        $val = \Illuminate\Support\Facades\Validator::make($request->all(),
            [
                'name' => 'required'
            ], [
                'name.required' => "名字不能為空"
            ]);
        if ($val->fails()) {
            return redirect('/adminyc/area/create')
                ->withErrors($val)
                ->withInput();
        }
    }

3.觀看效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM