app/Http/Controllers/ProfesorController.php
/** 
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'nombre'=>['required', 'string', 'min:3','max:50'],
            'apellidos'=>['required', 'string', 'min:5','max:80'],
            'localidad'=>['required', 'string', 'min:3','max:90'],
            'email'=>['required', 'string', 'min:5','max:60','unique:profesors,email']
        ]);
        try{
            Profesor::create($request->all());
        }catch(Exception $ex){
            return redirect()->route('profesores.index')->with("mensaje","Error:".$ex->getMessage());
        }
        return redirect()->route('profesores.index')->with("mensaje","Profesor creado");
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'nombre' => [ 'required' , 'string' , 'min:3' , 'max:50' ] , 'apellidos' => [ 'required' , 'string' , 'min:5' , 'max:80' ] , 'localidad' => [ 'required' , 'string' , 'min:3' , 'max:90' ] , 'email' => [ 'required' , 'string' , 'min:5' , 'max:60' , 'unique:profesors,email' ] ] ) ; try { Profesor :: create ( $ request -> all ( ) ) ; } catch ( Exception $ ex ) { return redirect ( ) -> route ( 'profesores.index' ) -> with ( " mensaje " , " Error: " . $ ex -> getMessage ( ) ) ; } return redirect ( ) -> route ( 'profesores.index' ) -> with ( " mensaje " , " Profesor creado " ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//1.- Validamos //2.- Procesamos