如何在Laravel 5.2中使用自定义服务提供程序

I am creating a Laravel app that needs to communicate with a remote (in-house) service via API.

This API needs to be authenticated at least once per session, and after that other calls can work fine.

I think the best way is to use Laravel's service providers to do this, but I'm open to other solutions.

What I would like:

What I would like is a way to have this Service available for use whenever. I don't want to have to put the service in the parameters of a controller's method if I can avoid it. Something like this:

use MyServiceProvider;

class SomeController extends Controller 
{
    public function someMethod ()
    {
        MyServiceProvider::method();
    }
}

I can post what I've started doing thus far, if needed - but I'd rather focus on doing what I want rather than fixing what I did wrong.

inb4: I did read the docs.

查看全部
doukezi4606
doukezi4606
2016/02/24 22:04
  • laravel
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复