app/Http/Controllers/recursoshumanos/rrhcontratocontroller.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([
            'descripcion'=>'required',
         'rrhempleado_id'=>'required'
         ,'rrhtipocontrato_id'=>'required',
         'sueldo'=>'required']);
        try {
            DB::beginTransaction();
            $rrhcontrato = Rrhcontrato::Create($request->all());
            if ($request->archivo) {
                $image = $request->file('archivo')->store('public/archivos/contratos');
                $url = Storage::url($image);
                $rrhcontrato->archivo = $url;
            }
            $rrhcontrato->save();
            DB::commit();
            return redirect()->route('rhcontratos.index');
        } catch (\Exception $exception) {
            DB::rollback();
            return  redirect()->back()->with('error', "Error" . $exception->getMessage());
        }
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'descripcion' => 'required' , 'rrhempleado_id' => 'required' , 'rrhtipocontrato_id' => 'required' , 'sueldo' => 'required' ] ) ; try { DB :: beginTransaction ( ) ; $ rrhcontrato = Rrhcontrato :: Create ( $ request -> all ( ) ) ; if ( $ request -> archivo ) { $ image = $ request -> file ( 'archivo' ) -> store ( 'public/archivos/contratos' ) ; $ url = Storage :: url ( $ image ) ; $ rrhcontrato -> archivo = $ url ; } $ rrhcontrato -> save ( ) ; DB :: commit ( ) ; return redirect ( ) -> route ( 'rhcontratos.index' ) ; } catch ( \ Exception $ exception ) { DB :: rollback ( ) ; return redirect ( ) -> back ( ) -> with ( 'error' , " Error " . $ exception -> getMessage ( ) ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .