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));
What is the right way to define the event? Thank you.