hemend/laravel-api is a Laravel package for generate api with service & version & method base.
It currently has 0 GitHub stars and 216 downloads on Packagist (latest version v5.1.2).
Install it with composer require hemend/laravel-api.
Discover more Laravel packages by hemend
or browse all Laravel packages to compare alternatives.
Last updated
Use shields for your packagist.org repository that shows how many times your project has been downloaded from packagist.org or its latest stable version.
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
database/seeders/DatabaseSeeder.php
In this section, you need to copy the required files from the package to your local path. If you execute the following command, you do not need to use commands after that:
php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=api
php artisan vendor:publish --provider="Hemend\Library\Laravel\Providers\LibraryServiceProvider" --tag=config
php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=config
php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=migrations
php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=seeders
php artisan vendor:publish --provider="Hemend\Api\ApiServiceProvider" --tag=models
public/index.php:$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
// $app->bind('path.public', function() {
// return __DIR__;
// });
app()->usePublicPath(__DIR__);
$kernel = $app->make(Kernel::class);
config/auth.php: ...
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
...
'guards' => [
...
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
...
],
...
'providers' => [
...
'users' => [
'driver' => 'eloquent',
'model' => App\Models\Users::class,
],
...
],
routes/api.php file and paste the following codes: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');
// });
});
|Keyword |Meaning |Example |
|----------------|-------------------------------|---------------------------------------------------|
|[Service] |Service name |Admin or Client ... |
|[Version] |Version of service |1 or 2 or ... or 99 |
|[Package] |Package from the server version |Auth or Account ... |
|[Endpoint] |Endpoint from the server version |SignIn or TokensGet ... |
|[Mode]? |Set the endpoint mode default(client) |admin or client |
|[Guard]? |Set the service guard default(api) |admin or client |
|[Flag]? |Set the permission flag default(private) |private or public or private_only or public_only |
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]
php artisan migrate
php artisan passport:install
php artisan db:seed
<?php
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']);
}
}
usage:
<?php
use App\Jobs\TrackableTest;
TrackableTest::dispatch();
Licensed under the MIT license, see LICENSE