How to use Costom Library in laravel
Route:
Controller :
Library :
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
Post a Comment