PHP code example of navjobs / transmit

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

    

navjobs / transmit example snippets


'providers' => [
    ...
    NavJobs\Transmit\TransmitServiceProvider::class,
];

use NavJobs\Transmit\Controller as ApiController;

class BookController extends ApiController
{
...

//Return the specified item, transformed
$this->respondWithItem($item, $optionalTransformer);

//Sets the status code to 201 and return the specified item, transformed
$this->respondWithItemCreated($item, $optionalTransformer);

//Return the specified collection, transformed
$this->respondWithCollection($collection, $optionalTransformer);

//Paginate the specified collection
$this->respondWithPaginatedCollection($collection, $optionalTransformer, $perPage = 10);

//Set the status code to 204, and return no content
$this->respondWithNoContent();

//Sets the status code to 403
$this->errorForbidden($optionalMessage);

//Sets the status code to 500
$this->errorInternalError($optionalMessage);

//Sets the status code to 404
$this->errorNotFound($optionalMessage);

//Sets the status code to 401
$this->errorUnauthorized($optionalMessage);

//Sets the status code to 400
$this->errorWrongArgs($optionalMessage);

//Eager loads the specified loquentModel, $provided query Builder
$this->applyParameters($queryBuilder, $parameters);

use NavJobs\LaravelApi\Transformer as BaseTransformer;

class BookTransformer extends BaseTransformer
...

//Pass in either an array or csv string
//Returns an array of 



namespace App\Book\Http\Books\Controllers;

use Exception;
use Illuminate\Http\Request;
use App\Book\Domain\Books\Entities\Book;
use App\Book\Transformers\BookTransformer;
use App\Book\Http\Books\Requests\BookRequest;
use NavJobs\Transmit\Controller as ApiController;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class BookController extends ApiController
{
    protected $bookModel;
    protected $transformer;
    protected $fractal;

    /**
     * @param Book $bookModel
     * @param BookTransformer $transformer
     */
    public function __construct(Book $bookModel, BookTransformer $transformer)
    {
        parent::__construct();

        $this->transformer = $transformer;
        $this->bookModel = $bookModel;
    }

    /**
     * Show a list of Books.
     *
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        $public function store(BookRequest $request)
    {
        $book = $this->bookModel->create($request->all());

        return $this->respondWithItemCreated($book, $this->transformer);
    }


    /**
     * Handle the request to update a Book.
     *
     * @param BookRequest $request
     * @param $bookId
     * @return mixed
     */
    public function update(BookRequest $request, $bookId)
    {
        try {
            $book = $this->bookModel->findOrFail($bookId);
        } catch (ModelNotFoundException $e) {
            return $this->errorNotFound();
        }

        $book->update($request->all());

        return $this->respondWithNoContent();
    }

    /**
     * Handle the request to delete a Book.
     *
     * @param $bookId
     * @return mixed
     */
    public function destroy($bookId)
    {
        try {
            $book = $this->bookModel->findOrFail($bookId);
        } catch (ModelNotFoundException $e) {
            return $this->errorNotFound();
        }

        try {
            $book->delete();
        } catch (Exception $e) {
            return $this->errorInternalError();
        }

        return $this->respondWithNoContent();
    }
}

$this->fractal;
bash
php artisan vendor:publish --provider="NavJobs\Transmit\TransmitServiceProvider"