Niall
Niall

Reputation: 518

Laravel - Using Guzzle

I want to make a laravel project that consumes an API. Ive seen plenty of examples online of using Guzzle but I am not quite sure where to actually write the code examples I've seen. Say for example on this site (The section on Interacting Githubs API) Where would I place this code in a Laravel project?

Upvotes: 0

Views: 617

Answers (2)

Fabio Antunes
Fabio Antunes

Reputation: 22882

It depends, if it's a simple call without logic you could do that on your controller.

But if you are going to re-use it again and again you could either create a parent controller and extend all your controllers from it, or create a class and then inject it on your controllers and other classes so you can use it. One thing I can assure keep this API calls way from your eloquent models.

Upvotes: 1

vnay92
vnay92

Reputation: 318

Where you place your code depends on what you are building and how you are building it. It actually comes down to the Coding Pattern you use. Mostly people use MVC pattern while using Laravel. So, it is safe to say that you write this code in your controller.

But that's really left to you and the pattern you want to follow.

Upvotes: 1

Related Questions