D
D
dk-web2019-02-16 00:44:30
Laravel
dk-web, 2019-02-16 00:44:30

Why can't I call Event via post request?

On the client

fire() {
        axios.get( APIENDPOINT + '/fired2').then((response)=>{
         this.status = response.data.message;
              })

On server
Route::get('/fired2', function () {
    NewUserRegistered::dispatch('lalla');
    return response()->json([
        'message' => 'Successfully fired through api (get)!',
         ], 201);
});

Everything works, everything flies into the pusher and back.
But.
Route::post('/fired3', function (Request $request) {
    return response()->json([
        'message' =>$request->message // данные получаю нормально
        ], 201);
    // NewUserRegistered::dispatch($request->input('message'));
    event(new  NewUserRegistered($request->message);
});

in the component
fire2() {
        axios.post( APIENDPOINT + '/fired3', {'message':this.message}).then((response)=>{
         this.status = response.data.message;
    })

Event does not work.
How then in Event to transfer the data from the form? Everything goes into $request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2019-02-16
@dk-web

Install IDE.
She will immediately tell you that after return comes Unreachable code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question