If you want to create a service provider then the way I like to think about it, is you are just creating a class you can use in alot of places (through dependency injection).
You should start by simply creating a php class, and making the functionality. Service providers come in handy when your class suddenly gets arguments it needs in the constructor. What is nice is you can create the service provider which allows you to tell the application what dependencies your class needs and get them for you.
You have the added advantage of being able to specify if you want the class to be a single instance that you use throughout the application, or if you want a new instance each time it is used.
If you have a specific question about something that doesn't make sense to you, then let us know and I'm sure someone will be able to answer.
Let me give you a practical example though so you have an idea of what you might do. Let's say I am creating an API, and I want to be able to send json responses.
I have a basic idea of the functionality I want to I create an interface called ApiServiceInterface and I put some functions in there. Then I create an ApiService that implements that Interface. I end up with some stuff like this:
public function respond($data, $headers = [])
{
return response()->json($data, $this->getStatusCode(), $headers);
}
Anyway.. now I want to be able to use this in my controller... so I make a service provider file so I can do a bind.
$this->app->bind('Acme\Api\Services\Interfaces\ApiServiceInterface', function ($app) {
return new ApiService();
});
Then I add this file to my app.php config file so the application knows to load it up.
'Acme\Api\Providers\ApiServiceProvider',
What this does is it tells laravel that anytime someone injects the ApiServiceInterface into a constructor or function etc, then to return a new ApiService. If you had dependencies for ApiService then you would specify those too... for example you would return this instead if for some reason your ApiService needed the request in the constructor.
return new ApiService(
$app['Illuminate\Http\Request']
);
So now you can use it like this in your controller
protected $api;
function __construct(ApiServiceInterface $api)
{
$this->api = $api;
}
and in your actions you can do something like this:
public function hello()
{
return $this->api->respond(['message' => 'hello']);
}
Hopefully my explanation here makes some sense and is somewhat accurate. I simplified the explanations on many things because I just wanted to describe a practical usage rather then go into all the benefits and various ways you can implement things. Let us know if you have a more specific question.