PHP code example of omidgfx / open-responder

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

    

omidgfx / open-responder example snippets


// before
use Flugg\Responder\Responder;

// after
use Omidgfx\Responder\Responder;

use Omidgfx\Responder\Http\MakesResponses;

class BookController
{
    use MakesResponses;

    public function index()
    {
        return $this->success(Book::all(), BookTransformer::class);
    }
}

use Omidgfx\Responder\Facades\Responder;

return Responder::success(Book::all(), BookTransformer::class)->respond(200);

return $this->error('page_not_found')->respond(404);
// or
return this->error(123, 'Something broke.')->respond(500);

use Omidgfx\Responder\Transformers\Transformer;

class BookTransformer extends Transformer
{
    protected $relations = [
        'author' => AuthorTransformer::class,
    ];

    protected $load = [
        'chapters',
    ];

    public function transform(Book $book)
    {
        return [
            'id' => (int) $book->id,
            'title' => $book->title,
        ];
    }
}
bash
php artisan vendor:publish --provider="Omidgfx\Responder\ResponderServiceProvider" --tag=config