PHP code example of motrack / hoodie

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

    

motrack / hoodie example snippets


Motrack\Hoodie\Providers\HoodieServiceProvider::class,

"aliases": {
    "Hoodie" => Motrack\Hoodie\Facades\Hoodie::class
}

use Motrack\Hoodie\Facades\Hoodie

    public function doFunction(): JsonResponse
    {
        ...
        return Hoodie::respondSuccess();
    }

return Hoodie::respondSuccess('Success!', 200, ['token' => $token, 'platform' => 'core']);

return Hoodie::respondError('Something went wrong!', 500, $exception, $headers );

use App\Http\Resources\PostResource; // the Json Resource you've provided for the result

class PostController extends Controller
{
    ...
    public function show(Post $post): JsonResponse
    {
        return Hoodie::respondWithResource(new PostResource($post) , 'Post Created Successfully', 201 , ['my_custom_header' => 'header_value']);
    }
    ...
}

use App\Http\Resources\PostCollection; // the Json Collection you've provided for the result

class PostController extends Controller
{
    public function index(): JsonResponse
    {
        return Hoodie::respondWithResourceCollection(new PostCollection(Post::paginate()) , 'List of Posts Retrieved Successfully', 200 , ['my_custom_header' => 'header_value']);
    }
    ...
}