Skip to content

ibnudirsan/Handler-Sanctum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Sanctum API Handler

Latest Version on Packagist Size Code on Packagist issues on Packagist follower on Packagist discussions on Packagist commit on Packagist license on Packagist

Cara menggunakannya :

install Package composer require ibnudirsan/lara-handler-sanctum

Ganti baris kode program ini :

// bootstrap/app.php

<?php

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class,
);

Menjadi seperti ini :

// bootstrap/app.php

<?php

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    Ibnudirsan\LaraHandlerSanctum\Exceptions\HandlerSanctumException::class,
    App\Exceptions\Handler::class,
);

Response Json

    /**
     * Method yang dapat digunakan
     */
    return ResponseJson::cretae($result);
    return ResponseJson::read($result);
    return ResponseJson::show($result);
    return ResponseJson::update();
    return ResponseJson::delete();

Usage Example :

// App/Http/Controllers/usersController.php

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Ibnudirsan\LaraHandlerSanctum\Halper\ResponseJson;

class usersController extends Controller
{
    public function getUser($id)
    {
        $result = User::where('id',$id)->first();
            return ResponseJson::read($result);
    }
}
// Contoh Return Json

{
    "app": {
        "info": {
            "error": false,
            "Status": "Read Data",
            "httpcode": 200,
            "Message": "Successfully Read Data"
        },
        "result": {
            "data": {
                "name": "ibnudirsan",
                "email": "[email protected]"
            }
        }
    }
}

Publish

Publish package configuration php php artisan vendor:publish --tag=handler-sanctum-config

Secara otomatis akan membuat file handler.php

// config/handler.php

<?php

return [
    
    'hidden' => [
        'email_verified_at',
        'created_at',
        'updated_at',
    ]
];

Note :

  • Di file ini bisa menambahkan atau menguragi filed yang di hidden.