0

How do you define event controller like in the route? I'm following this tutorial and the code in route is something like this where you can directly access an event.

Route web.php

Route::get('/sender', function(){
    return view('sender');
});
Route::post('/sender', function(){
    $message = request()->message;
    return event(new App\Events\PusherEvent($message));    
});

So I tried to use a controller instead. What I did was :

Route web.php

Route::get('/sender', 'TestingController@index');
Route::post('/sender', 'TestingController@index');

Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestingController extends Controller
{
    public function index(Request $message){
        if($message){
            return event(new App\Events\PusherEvent($message));
        }
        return view('sender');
    }
}

But an error appear at controller because of return event(new App\Events\PusherEvent($message));

enter image description here

What is the right way to define the event? Thank you.

4
  • can you attach the error message? Commented Sep 3, 2020 at 9:07
  • 2
    $message = request()->message; to $message->message in controler maybe ?? Commented Sep 3, 2020 at 9:08
  • @AlzafanChristian You are right! That is the cause. Thank you! Commented Sep 3, 2020 at 9:12
  • you're welcome, good luck.. Commented Sep 3, 2020 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.