PHP code example of hemend / laravel-api

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

    

hemend / laravel-api example snippets


php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=api
php artisan vendor:publish --provider="Hemend\Library\Laravel\Providers\LibraryServiceProvider" --tag=config

$app = t the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

$kernel = $app->make(Kernel::class);

    ...
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
    ...
    'guards' => [
    ...
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ...
    ],
    ...
    'providers' => [
    ...
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\Users::class,
        ],
    ...
    ],

function callApiRoute($route_name) {
    Route::any('/{service}/{version}/{endpoint}', 'Api')->where([
        'service' => '[a-z][a-zA-Z0-9]+',
        'version' => '[1-9][0-9]{0,1}',
        'endpoint' => '([a-z][a-zA-Z0-9]+(\/?[a-z][a-zA-Z0-9]+){0,6})'
    ])->name($route_name);
}

Route::group(['namespace' => 'Hemend\Api\Controllers\\'], function ($router) {
    callApiRoute('Api');

//    Route::group(['prefix' => 'demo'], function ($router) {
//        callApiRoute('DemoApi');
//    });
});

php artisan make:api-basic [Service] [Version] --mode=[Mode] --guard=[Guard]

php artisan make:api-maker [Service] [Version] [Package] [Endpoint] --flag=[Flag]

php artisan make:api-endpoint [Service] [Version] [Package] [Endpoint] --flag=[Flag]

php artisan make:api-service [Service]

php artisan make:api-version [Service] [Version]

php artisan api:acl-collect [Service]

- app/Models/User.php
- database/migrations/2014_10_12_000000_create_users_table.php
- database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php
shell
php artisan migrate
php artisan passport:install
php artisan db:seed --class=UsersSeeder
shell


namespace App\Jobs;

use Hemend\Api\Interfaces\TrackableJob;
use Hemend\Api\Traits\TrackableQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class TrackableTest implements ShouldQueue, TrackableJob
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, TrackableQueue;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        $this->prepareTracker();
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        $max = mt_rand(5, 30);
        $this->setProgressMax($max);

        for ($i = 0; $i <= $max; $i += 1) {
            sleep(1); // Some Long Operations
            $this->setProgressNow($i);
        }

        $this->setOutput(['total' => $max, 'other' => 'parameter']);
    }
}
shell


use App\Jobs\TrackableTest;

TrackableTest::dispatch();