marcreichel / igdb-laravel

Simplify the integration of the IGDB API into your Laravel app. Including IGDB webhook support.
https://marcreichel.dev/docs/igdb-laravel
MIT License
104 stars 22 forks source link

Where do i place "Game::createWebhook"? #44

Closed adzay closed 2 years ago

adzay commented 2 years ago

I want to implement Webhooks but it is not clear where to place the below:

use MarcReichel\IGDBLaravel\Models\Game;

Game::createWebhook(route('handle-webhook'), 'create');

I put it in my web.php (routes file) but that resulted in the below error:

Symfony\Component\Routing\Exception\RouteNotFoundException
Route [handle-webhook] not defined.
marcreichel commented 2 years ago

Hi, I'm sorry the docs are not clear about that. I will adjust them accordingly.

The createWebhook can be called inside of a controller method for example.

Example 1:

class ExampleController extends Controller {
    public function store()
    {
        Game::createWebhook(/* ... */);
    }
}

Example 2: (directly inside a route)

Route::post('your-route', function() {
    Game::createWebhook(/* ... */);
});

Just make sure you have done the initial configuration and have set up the route to handle incoming wenhooks.

I'm currently working on the next major version of this package which will have a huge improvement on how to work with webhooks (for example create them via the artisan CLI). Stay tuned 👍🏼

I hope I could help. If there are any unanswered questions feel free to ask and I will do my best to answer them. 💪🏼

adzay commented 2 years ago

Awesome, I see you have posted the update! looking forward to trying over the weekend (cant do it now).

marcreichel commented 2 years ago

Yeah, the new version is up and as already mentioned it contains a bunch of improvements for webhooks. The package also registers the necessary route itself now which makes it easier to start of with webhooks. 👍🏼

Just let me know what you think when you get your hands on the new version 🙂