PHP code example of khazhinov / laravel-lighty

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

    

khazhinov / laravel-lighty example snippets




namespace App\Exceptions;

use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Configuration\Exceptions as BaseExceptions;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
//use Sentry\Laravel\Integration;
use Khazhinov\LaravelLighty\Exceptions\JsonExceptionHandler;
use Throwable;

class ExceptionHandler extends JsonExceptionHandler
{
    public int $json_flags = JSON_UNESCAPED_SLASHES ^ JSON_UNESCAPED_UNICODE ^ JSON_THROW_ON_ERROR;

    public function __invoke(BaseExceptions $exceptions): BaseExceptions
    {
        $exceptions->renderable(
            fn(Throwable $exception, ?Request $request = null) => $this->jsonRender($request, $exception)
        );

        return $exceptions;
    }

    protected function reportSentry(BaseExceptions $exceptions): void
    {
//        $exceptions->reportable(
//            fn (Throwable $e) => Integration::captureUnhandledException($e)
//        );
    }

    protected function registerErrorViewPaths(): void
    {
        View::replaceNamespace(
            'errors',
            collect(config('view.paths'))
                ->map(fn (string $path) => "$path/errors")
                ->push($this->vendorViews())
                ->all()
        );
    }

    protected function vendorViews(): string
    {
        return __DIR__ . '/../../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views';
    }
}


#/api/v1.0/testEntities
Route::group([
    "namespace" => "TestEntity",
    "prefix" => "/testEntities",
    "as" => "test_entities.",
], static function () {
    Route::get("/validations/{method?}", "TestEntityCRUDController@getValidations")->name("validations");

    Route::get("/", "TestEntityCRUDController@index")->name("index");
    Route::post("/search", "TestEntityCRUDController@index")->name("search");
    Route::post("/setPosition", "TestEntityCRUDController@setPosition")->name("set-position");

    Route::post("/", "TestEntityCRUDController@store")->name("store");
    Route::delete("/", "TestEntityCRUDController@bulkDestroy")->name("bulk-destroy");

    #/api/v1.0/testEntities/:key
    Route::group([
        "prefix" => "/{key}",
    ], static function () {
        Route::get("/", "TestEntityCRUDController@show")->name("show");
        Route::put("/", "TestEntityCRUDController@update")->name("update");
        Route::delete("/", "TestEntityCRUDController@destroy")->name("destroy");
    });
});



use Illuminate\Support\Facades\Route;


# /api/v1.0/
Route::group(["namespace" => "App\Http\Controllers\Api\V1_0", "prefix" => "/v1.0", "as" => "api.v1_0"], static function () {
    #/api/v1.0/testEntities
    Route::group([
        "namespace" => "TestEntity",
        "prefix" => "/testEntities",
        "as" => "test_entities.",
    ], static function () {
        Route::get("/validations/{method?}", "TestEntityCRUDController@getValidations")->name("validations");

        Route::get("/", "TestEntityCRUDController@index")->name("index");
        Route::post("/search", "TestEntityCRUDController@index")->name("search");
        Route::post("/setPosition", "TestEntityCRUDController@setPosition")->name("set-position");

        Route::post("/", "TestEntityCRUDController@store")->name("store");
        Route::delete("/", "TestEntityCRUDController@bulkDestroy")->name("bulk-destroy");

        #/api/v1.0/testEntities/:key
        Route::group([
            "prefix" => "/{key}",
        ], static function () {
            Route::get("/", "TestEntityCRUDController@show")->name("show");
            Route::put("/", "TestEntityCRUDController@update")->name("update");
            Route::delete("/", "TestEntityCRUDController@destroy")->name("destroy");
        });
    });
});
bash
php artisan vendor:publish --provider="Khazhinov\LaravelLighty\LaravelLightyServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Khazhinov\LaravelLighty\LaravelLightyServiceProvider" --tag="views"
bash
php artisan lighty:generator TestEntity v1.0 --migration