Laravel 5.7 validation makes nothing

My function works by itself but the validation is not executed. Does anyone know what I forgot to add?

This is a snippet of my code:

namespace AppHttpControllers;

use AppPlayer;
use AppTournament;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesAuth;


    public function store(Request $request)
    {
       $data=$request->all();
$validator = Validator::make($data, [
            'first_name' => 'alpha|min:2|max:30',
        ]);
        
        
        
        if(Auth::check()){

            $foo = Foo::create([
                'first_name' => $request->input('fist_name'),
                'last_name' => $request->input('last_name'),
            ]);
 
            if($foo){
                return redirect()->route('foo.show', ['foo'=> $foo->id])
                ->with('success' , 'Foo created!');
            }
 
        }
         
        return back()->withInput()->with('errors', 'Error when creating the foo');
    }

Laravel 5.7 validation makes nothing

Thanks in advance

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

try different approach like:

use IlluminateSupportFacadesValidator;

...
$data=$request->all();
$validator = Validator::make($data, [
            'first_name' => 'alpha|min:2|max:30',,  
        ]);

Method 2

    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'category' => 'required',
        ]);

        //validating input

        if ($validator->fails()) {
            return back()->with('toast_error', $validator->messages()->all()[0])->withInput();
        }
// more code to run when if statement is executed with true for validated data
    }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x