Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Wednesday, August 22, 2018

Get Service Instance Anywhere in Laravel

Inject Service Instance by Constructor


Code Example:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class MyController extends Controller
{
    protected $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function store(Request $request)
    {
        $response = $this->client->message()->send([
            'text' => $request->input('text'),
        ]);
    }
}