Search code examples
laravelvalidationlaravel-5laravel-validation

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 App\Http\Controllers;

use App\Player;
use App\Tournament;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;


    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');
    }

enter image description here

Thanks in advance


Solution

  • try different approach like:

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