app/Http/Controllers/Empresa/VisitaController.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();
        $data['estado_visita_id'] = 1;
        $data['empresa_id']       = auth()->user()->empresa_id;
        if (!$request->is('api/*')) {
            $data['fecha_inicio'] = Carbon::parse($data['fecha'] . ' ' . $data['horaEstimada'])->toDateTimeString();
            $data['fecha_fin']    = Carbon::parse($data['fecha'] . ' ' . $data['horaEstimada'])->addMinutes($data['tiempo_visita'])->toDateTimeString();
        }
        $visita    = Visita::create($data);
        $previsita = null;
        if ($request->is('api/*')) {
            $previsita = $visita->tipoVisita->plantillaPre->detalles()->with(['visita'=>function ($query) use ($visita) {
                $query->where('id', $visita->id);
            }])->orderBy('orden')->get();
        }
        $validate = true;
        $visita->vendedor->notify(new NuevaVisitaNotification($visita->id));
        return response()->json(compact('visita', 'validate', 'previsita'));
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ data [ 'estado_visita_id' ] = 1 ; $ data [ 'empresa_id' ] = auth ( ) -> user ( ) -> empresa_id ; if ( ! $ request -> is ( 'api/*' ) ) { $ data [ 'fecha_inicio' ] = Carbon :: parse ( $ data [ 'fecha' ] . ' ' . $ data [ 'horaEstimada' ] ) -> toDateTimeString ( ) ; $ data [ 'fecha_fin' ] = Carbon :: parse ( $ data [ 'fecha' ] . ' ' . $ data [ 'horaEstimada' ] ) -> addMinutes ( $ data [ 'tiempo_visita' ] ) -> toDateTimeString ( ) ; } $ visita = Visita :: create ( $ data ) ; $ previsita = null ; if ( $ request -> is ( 'api/*' ) ) { $ previsita = $ visita -> tipoVisita -> plantillaPre -> detalles ( ) -> with ( [ 'visita' => function ( $ query ) use ( $ visita ) { $ query -> where ( 'id' , $ visita -> id ) ; } ] ) -> orderBy ( 'orden' ) -> get ( ) ; } $ validate = true ; $ visita -> vendedor -> notify ( new NuevaVisitaNotification ( $ visita -> id ) ) ; return response ( ) -> json ( compact ( 'visita' , 'validate' , 'previsita' ) ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .