PHP code example of iqbalatma / laravel-utils

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

    

iqbalatma / laravel-utils example snippets


return [
    "target_enum_dir" => "app/Enums",
    "target_trait_dir" => "app/Traits",
    "target_abstract_dir" => "app/Contracts/Abstracts",
    "target_interface_dir" => "app/Contracts/Interfaces",
    "api_response" => [
        "payload_wrapper" => "payload",
        "meta_wrapper" => null
    ],
    "is_show_debug" => env("APP_DEBUG", false)
];



namespace App\Http\Controllers\API\Internal\Management;

use App\Http\APIResponse;
use App\Http\Controllers\ApiController;
use App\Models\Permission;
use App\Http\Resources\Internal\Management\Permissions\PermissionResourceCollection;

class PermissionController extends ApiController
{
    /**
     * @return APIResponse
     */
    public function index(): APIResponse
    {
        $data = Permission::all();

        return $this->response(
            new PermissionResourceCollection($data),
            "Get all data permission successfully"
        );
    }
}



namespace App\Services\V1;

use Iqbalatma\LaravelUtils\Interfaces\ResponseCodeInterface;
use Symfony\Component\HttpFoundation\Response;

/**
 * @method static ResponseCodeInterface ERR_NOT_FOUND()
 */
class ResponseCode extends \Iqbalatma\LaravelUtils\ResponseCode
{
    protected const ERR_NOT_FOUND = "ERR_NOT_FOUND";


    /**
     * @return void
     */
    protected function mapHttpCode(): void
    {
        $this->httpCode = match ($this->name) {
            self::ERR_NOT_FOUND => Response::HTTP_NOT_FOUND,
            default => null
        };

        if ($this->httpCode === null) {
            parent::mapHttpCode();
        }
    }
}

$this->renderable(function (NotFoundHttpException $e) {
    if (request()->expectsJson()) {
        return new APIResponse(
            null,
            message: $e->getMessage(),
            responseCode: ResponseCode::ERR_NOT_FOUND(),
            exception: $e
        );
    }
});

...
"api_response" => [
    "payload_wrapper" => "payload",
    "meta_wrapper" => "meta"
],
"is_show_debug" => env("APP_DEBUG", false)
...

ddapi($data);
ddapi($data, $data2);
shell
php artisan make:enum Gender
php artisan make:enum Gender --type=string
shell
php artisan make:trait HasInstitution
shell
php artisan make:abstract BaseService
shell
php artisan make:inteface IRouter
shell
php artisan utils:publish-stub