PHP code example of galaxydevs / laravel-api-master

1. Go to this page and download the library: Download galaxydevs/laravel-api-master 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/ */

    

galaxydevs / laravel-api-master example snippets


use Psy\Util\Json;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

public function _errorMessage($responseCode = 400, $message = 'Bad Request'){
    $body = Json::encode(
        array(
            "success" => false,
            "responseCode" => $responseCode,
            'message' => $message
        )
    );
    echo $body;
    die;
}

public function render($request, Exception $exception)
{
    if($exception instanceof NotFoundHttpException){
        $this->_errorMessage(404,'Page Not Found');
    }

    if ($exception instanceof MethodNotAllowedHttpException) {
        $this->_errorMessage(405,'Method is not allowed for the requested route');
    }

    return parent::render($request, $exception);
}

'api.auth' => \DevDr\ApiCrudGenerator\Middleware\CheckAuth::class,

php artisan crud:api-generator User

$user = $request->get('users');

public static function findIdentityByAccessToken($token, $type = null)
{
    return static::where(['auth_token' => $token])->first();
}

$user = $this->_checkAuth();