PHP code example of mmanos / laravel-api

1. Go to this page and download the library: Download mmanos/laravel-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mmanos / laravel-api example snippets


'aliases' => array(
	// ...
	'Api' => 'Mmanos\Api\Api',
)

'LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware'

use Exception;
use Mmanos\Api\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler {
	...
}

use Illuminate\Routing\Controller;
use Mmanos\Api\ControllerTrait;

class BaseController extends Controller
{
	use ControllerTrait;
}

$this->response()->header('Example-Header', 'Example value');

Api::abort(404);

Api::abort(403);

Api::abort(403, 'Access denied to scope: users:write');

Api::abort(422, $validator->errors());

$this->beforeFilter('protect');

$this->beforeFilter('checkscope:users.write');

Api::bindTransformer('User', 'Transformers\User');

class User extends Eloquent
{
	public $transformer = 'Transformers\User';
}

namespace Transformers;

class User
{
	public function transform($object, $request)
	{
		$output = $object->toArray();
		$output['id'] = (int) $output['id'];
		$output['created_at'] = $object->created_at->setTimezone('UTC')->toISO8601String();
		$output['updated_at'] = $object->updated_at->setTimezone('UTC')->toISO8601String();
		
		if ($request->input('hide_email')) {
			unset($output['email']);
		}
		
		return $output;
	}
}

$users_array = Api::internal('api/users')->get();

$users_array = Api::internal('api/users', array('sort' => 'newest'))->get();

$new_user_array = Api::internal('api/users', array('email' => '[email protected]'))->post();
console
$ php artisan vendor:publish --provider="LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider"
console
$ php artisan vendor:publish --provider="Mmanos\Api\ApiServiceProvider"
console
$ php artisan migrate