app/Http/Controllers/EmpleadoController.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)
    {
        $campos=[
            'nombre'=>'required|string',
            'apellidoP'=>'required|string|max:100',
            'apellidoM'=>'required|string|max:100',
            'correo'=>'required|email',
            'foto'=>'required|max:10000|mimes:jpeg,png,gif'
        ];
        $mensaje=[
            'required'=>'El :attribute es obligatorio',
            'email'=>'Debe tener el siguiente formato ejemplo@guayo.com',
            'foto.required'=>'La foto es requerida.'
        ];
        $this->validate($request, $campos, $mensaje);
        $datosEmpleado = request()->except('_token');
        if($request->hasFile('foto')){
            $datosEmpleado['foto'] = $request->file('foto')->store('uploads','public');
        }
        Empleado::insert($datosEmpleado);
        return redirect('empleado')->with('mensaje','Empleado creado correctamante.');
    }
public function store ( Request $ request ) { $ campos = [ 'nombre' => 'required|string' , 'apellidoP' => 'required|string|max:100' , 'apellidoM' => 'required|string|max:100' , 'correo' => 'required|email' , 'foto' => 'required|max:10000|mimes:jpeg,png,gif' ] ; $ mensaje = [ 'required' => 'El :attribute es obligatorio' , 'email' => 'Debe tener el siguiente formato ejemplo@guayo.com' , 'foto.required' => 'La foto es requerida.' ] ; $ this -> validate ( $ request , $ campos , $ mensaje ) ; $ datosEmpleado = request ( ) -> except ( '_token' ) ; if ( $ request -> hasFile ( 'foto' ) ) { $ datosEmpleado [ 'foto' ] = $ request -> file ( 'foto' ) -> store ( 'uploads' , 'public' ) ; } Empleado :: insert ( $ datosEmpleado ) ; return redirect ( 'empleado' ) -> with ( 'mensaje' , 'Empleado creado correctamante.' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//data validation //we get the data //how to catch the photo //we store it in the directory /public/uploads //JSON response //return response()->json($datosEmpleado);