How to use Costom Library in laravel

Route:

Route::group([ 'prefix' => '', 'namespace' => 'Front'] , function (){    Route::get('/', 'NewsController@index');});

Controller :

<?php
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller;use App\Library\API\News_Api;use Illuminate\Http\Request;
class NewsController extends Controller{    public function index(){        $news_details = [];        $news = (new News_Api())->News_get($news_details);        dd($news);    }}

Library :

<?php
namespace App\Library\API;
use GuzzleHttp\Client;
class News_Api{    function News_get($news_details){
        $news= (new Client())->request('GET',env('NEWS_BASE_URL') ,[            'query' => [                'query1' => ''            ]        ]);
        return json_decode((string) $news->getBody());

    }}

Comments

Popular posts from this blog

Displaying a flash message after redirect in Codeigniter

What is required for it startup company ?

how to export html data to pdf in angularjs and javascript