InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.78k stars 812 forks source link

scaffold and Class 'App\Http\Controllers\AppBaseController' not found` #539

Closed arianpasquali closed 5 years ago

arianpasquali commented 6 years ago

I'm new to laravel-generator. I created a simple project following the documentation instructions. This is my project setup with dependencies versions.

"require": { "php": ">=7.1.3", "fideloper/proxy": "~4.0", "infyomlabs/adminlte-templates": "5.6.x-dev", "infyomlabs/laravel-generator": "5.6.x-dev", "laravel/framework": "5.6.*", "laravel/tinker": "~1.0", "laravelcollective/html": "5.6.0" },

After running scaffold for a simple model I keep receiving AppBaseController' not found in the generated controller.

These are the steps to reproduce.

php artisan infyom:scaffold Project --fieldsFile=fields_projects.json php artisan migrate

fields_projects.json looks like this.

[
    {
        "name": "id",
        "dbType": "increments",
        "htmlType": "",
        "validations": "",
        "searchable": false,
        "fillable": false,
        "primary": true,
        "inForm": false,
        "inIndex": false
    },
    {
        "name": "title",
        "dbType": "string",
        "htmlType": "text",
        "validations": "required",
        "searchable": true
    },
    {
        "name": "body",
        "dbType": "text",
        "htmlType": "textarea"
    }
]

serve the app php artisan serve

go to http://127.0.0.1:8000/projects

get this error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Class 'App\Http\Controllers\AppBaseController' not found

I've checked previous related issues here in the repository and tried different suggestions, but none could fix it. It seems I m missing something obvious here. Maybe others might be facing the same issue.

dhcmega commented 6 years ago

If you don't need to print json responses (mostly for api calls) you can just use regular Controller as in any other regular laravel controller.

mitulgolakiya commented 6 years ago

@arianpasquali have you run this step? http://labs.infyom.com/laravelgenerator/docs/5.6/installation#publish

And all above steps before this step?

HenriPablo commented 6 years ago

... any progress on this issue? Just starting my first app and run into this exact same problem. Are there any workarounds for this?

horaciod commented 6 years ago

i have the same problem . Changing the AppBaseController by Controller fix the issue .

Another solution : add use InfyOm\Generator\Controller\AppBaseController;

in top of the controller.

mitulgolakiya commented 5 years ago

In this step, http://labs.infyom.com/laravelgenerator/docs/5.8/installation#publish, AppBaseController.php is published. Make sure, you have run this step.

If the problem persists, report it with some more details.

japc-74 commented 5 years ago

Hello @mitulgolakiya I'm facing the same issue, I'd used php artisan infyom:api_scaffold $MODEL_NAME --datatables=true --fromTable --tableName=$TABLE_NAME

where $MODEL_NAME and $TABLE_NAME are properly setted. the result is:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Class 'InfyOm\Generator\Controller\AppBaseController' not found

On the controller I have:

use App\DataTables\AlergenosDataTable; use App\Http\Requests; use App\Http\Requests\CreateAlergenosRequest; use App\Http\Requests\UpdateAlergenosRequest; use App\Repositories\AlergenosRepository; use Flash; use InfyOm\Generator\Controller\AppBaseController; use Response;

I would like to know if someone has faced the same issue, and get resolved already?

I ran http://labs.infyom.com/laravelgenerator/docs/5.8/installation#publish but the problem persists.

mitulgolakiya commented 5 years ago

@japc-74 did you published and customized the templates?

japc-74 commented 5 years ago

@mitulgolakiya I ran php artisan infyom:publish

japc-74 commented 5 years ago

@mitulgolakiya you mean if I made changes to the templates provided by your generator, the response is nope.

mitulgolakiya commented 5 years ago

@japc-74 not sure, what laravel version you are using, but something is really wrong with your templates. Because, the line,

use InfyOm\Generator\Controller\AppBaseController;

should not come because that line is not there in the current template which is here. https://github.com/InfyOmLabs/laravel-generator/blob/develop/templates/scaffold/controller/datatable_controller.stub#L11

In my opinion, you should double check your templates.

dhcmega commented 5 years ago

@japc-74 I hope this will guide you instead of adding more confusion.

AppBaseController is there only to add JSON responses for APIs, so if you are not using APIs, you don't need it and you can just extend Controller.

AppBaseController should be present in your Http/Controllers directory. If your namespaces are ok, you don't need the "use" line. If you need to add it, then the "use" line should be pointing somewhere in your Http directory and not the vendor directory.

You said you have ran the publish script, did you get the files published as explained in the docs?

Let me know if you need further help.

japc-74 commented 5 years ago

@mitulgolakiya @dhcmega thank you both guys! The issue was because templates, I did change to CoreUI by using the BoilerPlate and works just great!

is an amazing tool, saves me a lot of time.

alamin209 commented 4 years ago

Did you try to publish your my artisan command php artisan infyom:publish and this php artisan vendor:publish .I try and it work fine

3x1io commented 3 years ago

@alamin209 Thanks bro it's work fine now.