Last active
August 31, 2017 05:54
-
-
Save gayanvirajith/2dd2e08711035597112f42d5c64f1450 to your computer and use it in GitHub Desktop.
Laravel is API call trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
use Illuminate\Http\Request; | |
trait RestTrait | |
{ | |
/** | |
* Determines if request is an api call. | |
* | |
* If the request URI contains '/api/v'. | |
* | |
* @param Request $request | |
* @return bool | |
*/ | |
protected function isApiCall(Request $request) | |
{ | |
return strpos($request->getUri(), '/api/v') !== false; | |
} | |
} | |
// Credit https://laracasts.com/discuss/channels/code-review/best-way-to-handle-rest-api-errors-throwed-from-controller-or-exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment