Provide information & explanation
I have added entrust package and wanted to create a Role Transformer as per guide by Dingo Api. Insted of getting a json formatted by the transformer, I am getting an array.
code samples
This is my first Dingo Api implementation. This is my
RoleTrasnformer class
namespace App\Api\V1\Transformers;
use League\Fractal\TransformerAbstract;
use App\Role;
class RoleTransformer extends TransformerAbstract
{
public function transform(Role $role)
{
return [
'role_id' => (int)$role->id,
'name' => $role->name
];
}
}
This is RoleController
namespace App\Http\Controllers;
use Dingo\Api\Routing\Helpers;
use Illuminate\Http\Request;
use Dingo\Api\Http\Response;
use App\Role;
use App\Http\Requests;
use App\Api\V1\Transformers\RoleTransformer;
class RoleController extends Controller
{
use Helpers;
public function index(){
$roles = Role::all();
return $this->response->collection($roles, new RoleTransformer())
->setStatusCode(200);
}
}
Though I was supposed to get only role_id and name
Found the solution. In config/api.php, url prefix was set as 'prefix' => env('API_PREFIX', 'api'); but in my routes, I was testing without api prefix. As soon I set api in route, its working like a charm.
This is my first Dingo Api implementation. This is my
RoleTrasnformer
classThis is
RoleController
Though I was supposed to get only
role_id
andname
Not sure what I am doing wrong. Please help me to identify the glitch.
I've searched over the stackoverflow and other forums and it seems Dingo has issue with Laravel 5.2 but didn't get anything solid or how to solve it.