app/Http/Controllers/Empresa/TareasController.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)
    {
        $data = $request->all();
        if ($data['recordatorio']!=null) {
            $data['fecha_notificacion']=Carbon::parse($data['fecha'])->subMinutes($data['recordatorio'])->toDateTimeString();
        }
        $data['usuario_crea_id']=Auth::user()->id;
        if ($request->has('visita_id') && $data['visita_id']!=null) {
            $visita = Visita::find($request->get('visita_id'));
            $data['usuario_id']=$visita->usuario_id;
            $tarea=$visita->tareas()->create($data);
            if ($request->has('compartir') && $request->get('compartir')>0) {
                $tarea->usuarios_adicionales()->attach($request->get('compartir'));
            }
            if ($request->is('api/*')) {
                return response()->json(['created'=>true]);
            }
            return redirect('e/visita/'.$visita->id.'?pest=T')->with('mensaje', 'Datos de tarea guardados');
        } else {
            $data['usuario_id']=$data['usuario_id'];
            $data['visita_id']=0;
            $tarea=Tarea::create($data);
        }
        if ($request->has('compartir') && $request->get('compartir')>0) {
            $tarea->usuarios_adicionales()->attach($request->get('compartir'));
        }
        if ($request->is('api/*')) {
            return response()->json(['created'=>true]);
        }
        return back();
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; if ( $ data [ 'recordatorio' ] != null ) { $ data [ 'fecha_notificacion' ] = Carbon :: parse ( $ data [ 'fecha' ] ) -> subMinutes ( $ data [ 'recordatorio' ] ) -> toDateTimeString ( ) ; } $ data [ 'usuario_crea_id' ] = Auth :: user ( ) -> id ; if ( $ request -> has ( 'visita_id' ) && $ data [ 'visita_id' ] != null ) { $ visita = Visita :: find ( $ request -> get ( 'visita_id' ) ) ; $ data [ 'usuario_id' ] = $ visita -> usuario_id ; $ tarea = $ visita -> tareas ( ) -> create ( $ data ) ; if ( $ request -> has ( 'compartir' ) && $ request -> get ( 'compartir' ) > 0 ) { $ tarea -> usuarios_adicionales ( ) -> attach ( $ request -> get ( 'compartir' ) ) ; } if ( $ request -> is ( 'api/*' ) ) { return response ( ) -> json ( [ 'created' => true ] ) ; } return redirect ( 'e/visita/' . $ visita -> id . '?pest=T' ) -> with ( 'mensaje' , 'Datos de tarea guardados' ) ; } else { $ data [ 'usuario_id' ] = $ data [ 'usuario_id' ] ; $ data [ 'visita_id' ] = 0 ; $ tarea = Tarea :: create ( $ data ) ; } if ( $ request -> has ( 'compartir' ) && $ request -> get ( 'compartir' ) > 0 ) { $ tarea -> usuarios_adicionales ( ) -> attach ( $ request -> get ( 'compartir' ) ) ; } if ( $ request -> is ( 'api/*' ) ) { return response ( ) -> json ( [ 'created' => true ] ) ; } return back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .