ibnudirsan / handler-sanctum
Laravel Sanctum API Handler.
v3.2.6
2022-12-10 06:28 UTC
Requires
- php: ^8.0.2
- laravel/framework: ^9.0
README
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": "ibnudirsan@gmail.com"
}
}
}
}
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.