Controller Definition

For each Laravel model you want to provide API access to you will need to create a Controller.

This should be placed in the standard Laravel location e.g. App/Http/Controllers or a subdirectory. Our suggestion is to use App/Http/Controllers/Api

The controller definition is fairly simple

<?php
namespace App\Http\Controllers\Api;

use Restive\Http\Controllers\ApiController;

class DummySimpleController extends ApiController
{
    protected $modelName = '\\Restive\\Models\\DummySimple'; // an example of defining a custom model
    protected $request = ''; // we can define a custome Form Request class here
    protected $resource = ''; // we can define a custom resource class here
    protected $resourceCollection = ''; // we can define a custom resourceCollection class here
    protected paginator = ''; // we can define a custom paginator class here

The protected $modelName defines the Eloquent Model that will be used by the controller. The factory class used will try and resolve the model from either your projects App folder or from the App/Models folder, If the Model is in one of these folders there is no need to namespace the model name. e.g. you could just do

    protected $modelName = 'ModelName';

There is a console command available to create a stub controller.

The protected $request defines a FormRequest class that will be used to validate store/update requests. The factory class used will try and resolve the Form Request from the App/Http/Requests folder, although you can set this to any namespace that you want.

    protected $request = 'FormRequestName';

There is a console command available to create a stub Form Request.