Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot instantiate abstract class... #86

Open
enzonotario opened this issue Aug 5, 2016 · 5 comments
Open

Cannot instantiate abstract class... #86

enzonotario opened this issue Aug 5, 2016 · 5 comments
Labels

Comments

@enzonotario
Copy link

enzonotario commented Aug 5, 2016

Hi!, I'm trying to implement this in laravel but when I run php artisan route:list for example, I get:
Cannot instantiate abstract class Illuminate\Database\Eloquent\Model

I have a model called Piso:

<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Piso extends Model
{
    public $timestamps = false;
    protected $table = 'pisos';
    protected $primaryKey = 'id';

}

a PisoTransformer:

class PisoTransformer implements JsonApiMapping
{
    public function getClass()
    {
        return Piso::class;
    }

    public function getAlias()
    {
        return 'piso';
    }

    public function getAliasedProperties()
    {
        return [

        ];
    }

    public function getHideProperties()
    {
        return [

        ];
    }

    public function getIdProperties()
    {
        return ['id'];
    }

    public function getUrls()
    {
        return [
            'self' => ['name' => 'pisos.show', 'as_id' => 'id'],
            'pisos' => ['name' => 'pisos.index'],
        ];
    }

    public function getRelationships()
    {
        return [];
    }
}

}

In my routes.php I have: Route::resource('pisos', 'PisoController');

and in config/jsonapi.php:

<?php

use App\Models\Api\PisoTransformer;

return [
    PisoTransformer::class,
];

Can someone help me please??.. and sorry, I don't speak english so if anything is wrong...

Thanks!

@nilportugues
Copy link
Owner

nilportugues commented Aug 6, 2016

Everything looks OK to me.

@enzonotario mind sharing PisoController so I can try recreate the scenario? Maybe it's something there. You need to inherint the Controller provided by this package to make it work.

@enzonotario
Copy link
Author

enzonotario commented Aug 6, 2016

Yes, I have PisoController:

<?php namespace App\Http\Controllers;

use App\Models\Piso;
use NilPortugues\Laravel5\JsonApi\Controller\JsonApiController;

class PisoController extends JsonApiController
{
    /**
     * Return the Eloquent model that will be used
     * to model the JSON API resources.
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function getDataModel()
    {
        return new Piso();
    }
}

I use this package with https://github.com/jadjoubran/laravel5-angular-material-starter

@enzonotario
Copy link
Author

If I use the laravel5-jsonapi-dingo package, I get: "Action App\\Http\\Controllers\\PisoController@index not defined.",, with the same controller that extends JsonApiController..
I dont know why..
please help me!

@novs
Copy link

novs commented Aug 14, 2016

Check DB connection

@enzonotario
Copy link
Author

Yes, now it works... but I don't understand how to do validations. I create a Form Request but it doesn't work.. if I use the "manual validation" doesn't work too... can anyone give me an example of how to use this package with "business validations"?
For example, with the Employee model in the README, how can I validate that the email_address is unique? or whatever other validations?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants