Apiato: Naming conventions for Models in apiato

Created on 16 Aug 2017  路  3Comments  路  Source: apiato/apiato

Expected Behavior

Object is instanciated and inserted into the database.

Actual Behavior

Created a new Model (GeoRequestModel) with an unrelated name to the container (Demo) - which led to an issue during the creation of new instances:

"message": "Class App\\Containers\\GeoRequestModel\\Models\\GeoRequestModel does not exist",
"exception": "ReflectionException",

Steps to Reproduce the Problem

  • php artisan apiato:model → create a new model with a repository with a name unrelated to the container.
  • create a dummy route, controller method (and action) to instantiate the object

Solutions

  • Either provide a notice within the Artisan Command or take precautions for the user.

    • Naming: provide a naming convention in your documentation (also include the case multiple models in one container - i think you have to add the container name as prefix followed by an underscore and then the model name?)

    • Try to fix the naming and notify the user in the artisan command?


Hint: I am new to apiato, Laravel and php, so maybe this is common sense in this domain but it was quite new for me, I'd appreciate it if you could add a paragraph naming conventions for such things.

Help Suggestion

Most helpful comment

with the latest update for apiato/core (see here) this issue should be resolved..
If you are using the latest version of apiato/apiato just run composer update to generate the $container property for new (!!!!) repositories

All 3 comments

From the documentation http://apiato.io/components/repositories/

Note: If the Repository belongs to Model with a name different than its Container name, the Repository class of that Model must set the property $container and define the Container name.

Example:

<?php

namespace App\Containers\Authorization\Data\Repositories;

use App\Ship\Parents\Repositories\Repository;

class RoleRepository extends Repository
{
    protected $container = 'Authorization'; // the container name. Must be set when the model has different name than the container

    protected $fieldSearchable = [

    ];

}

Thanks for the example. I searched for the info in the models section an did not find it. 馃檪

with the latest update for apiato/core (see here) this issue should be resolved..
If you are using the latest version of apiato/apiato just run composer update to generate the $container property for new (!!!!) repositories

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mahmoudz picture Mahmoudz  路  7Comments

deviouspk picture deviouspk  路  6Comments

overbid picture overbid  路  4Comments

mvn-trungtran-dn picture mvn-trungtran-dn  路  6Comments

muhsenmaqsudi picture muhsenmaqsudi  路  7Comments