Skip to content

Instantly share code, notes, and snippets.

@gayanvirajith
Last active August 31, 2017 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gayanvirajith/2dd2e08711035597112f42d5c64f1450 to your computer and use it in GitHub Desktop.
Save gayanvirajith/2dd2e08711035597112f42d5c64f1450 to your computer and use it in GitHub Desktop.
Laravel is API call trait
<?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