PHP code example of kindharika / laravel-api-starter

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

    

kindharika / laravel-api-starter example snippets


use Kindharika\ApiStarter\Base\BaseModel;

class Post extends BaseModel
{
    protected $table = 'posts';
}

use Kindharika\ApiStarter\Base\BaseApiController;

class PostController extends BaseApiController
{
    // use sendSuccess() / sendError()
}

use Kindharika\ApiStarter\Base\BaseService;
use Kindharika\ApiStarter\Base\BaseServiceInterface;

class PostService extends BaseService implements BaseServiceInterface
{
    // implements dataTable, getById, create, update, delete
}

$posts = Post::datatable($request->all())->paginate(15);

use Kindharika\ApiStarter\Traits\FirebaseNotification;

class YourService
{
    use FirebaseNotification;

    public function notify($user)
    {
        $this->sendNotification($user, 'Title", "Body", "INFO");
    }
}

return [
    'namespace' => 'App',
    'uuid_version' => 4,
    'fcm' => [
        'enabled' => true,
        'server_key' => env('FCM_SERVER_KEY'),
        'endpoint' => 'https://fcm.googleapis.com/fcm/send',
    ],
    'datatable' => [
        'per_page' => 15,
        'default_sort_column' => 'created_at',
        'default_sort_direction' => 'desc',
    ],
];
bash
php artisan vendor:publish --tag=api-starter-config
bash
php artisan api:scaffold Post
bash
php artisan api:make-model Post
php artisan api:make-controller PostController --model=Post
php artisan api:make-service PostService --model=Post
php artisan api:make-request Post
php artisan api:make-migration Post
php artisan api:make-resource Post