最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

validate() method in laravel 10 can be used for custom validation errors but how? - Stack Overflow

programmeradmin3浏览0评论

i have a query regarding validate() method in laravel 10 how we are able to pass 2nd param to validate method for creating customer validation messages? i cant find anything regarding validate() in laravel 10 official docs where they should have explained the validate() method that whether it takes 2 params or 3 params and what we should pass in them, what should be the syntax. i even checked api docs but those docs are too complex man.I am unable to find validate() method in api docs may be it is getting created dynamically not hardcoded.. hahaha. shame on me but need answer, can someone help?

public function addUser(Request $req){
        $validated=$req->validate([
            'name'=>'required',
            'age'=>'required',
            'email'=>'required',
            'city'=>'required'
        ],
         [
           //2nd param
            'name.required'=> 'you name is xyz'
       ]);
        
        $user = DB::table('meenas')->insert([
            'name'=>$req->input('name'),
            'age'=>$req->input('age'),
            'email'=>$req->input('email'),
            'city'=>$req->input('city'),
        ]);
        if($user){
            return redirect()->route('showallusers')->with('true','user registered successfully');
        }
        else{
            return redirect()->route('addform')->with('false','Cant register user');
            //returb back()->with();
        }
    }
发布评论

评论列表(0)

  1. 暂无评论