PHP code example of abd-wazzan / laravel-api-boilerplate

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

    

abd-wazzan / laravel-api-boilerplate example snippets




namespace App\Http\Api\Controllers;

use App\Traits\ApiResponseHelpers;
use Illuminate\Http\JsonResponse;
use App\Http\Controller;

class ProductController extends Controller
{
    use ApiResponseHelper;

    public function index(): JsonResponse
    {
        return $this->okResponse();
    }
}



namespace App\Http\Api\Controllers;

use App\Helpers\ApiController;
use App\Traits\ApiResponseHelpers;
use Illuminate\Http\JsonResponse;
use App\Http\Controller;

/**
 * Class CategoryController
 * @group Category
 */
class CategoryController extends Controller
{
    use ApiResponseHelper;

    /**
     * Get Categories
     *
     * this request is used to get all categories.
     *
     * @queryParam filter[name]
     *
     * @usesPagination
     * @failedResponse
     * @forbiddenResponse
     * @throws \Illuminate\Auth\Access\AuthorizationException
     * @throws \Throwable
     */
    public function index(): Response
    {
        return CategoryResource::collection($categories->all());
    }

}



namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->loadMigrationsFrom([
            database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'Client',
        ]);
    }
}



namespace Shared\Enums;

enum MorphEnum: string
{
    case USER = 'user';
}



namespace App\Providers;

use Shared\Enums\MorphEnum;
use Domain\Client\Models\User;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Relation::morphMap([
            MorphEnum::USER->value => User::class,
        ]);
    }
}
bash
php artisan key:generate 
bash
php artisan serve