Is there a way use artisan to create a model or controller?

I was used Laravel. Seen the only way to make controller or model by hand copying from somewhere.

Slim is very slim and doesn’t contain any code generators. :slight_smile: If you are using Eloquent models, I’ve heard of people installing Artisan outside of Laravel (see this for example) but I’ve never bothered myself.

1 Like

Thanks. Slim as her name is one of the main reason I choose. I had read this article before this topic. It seems helpless. I am wondering how people create their own Model or Controller? By copying the sample code from somewhere else manually?

I just write them out by hand most of the time. Or if I have a class very similar from another project I’ll copy/paste it.

Another option is to create a separate project with the full Laravel project. Use Artisan to make your controllers and models, then just move the files it generates into your Slim project. You wouldn’t pollute your Slim project with any additional projects, you would have access to the Artisan generators, and the only extra time would be the second or two to copy the generated files from the fake Laravel project into your Slim project. You could even keep that Laravel project under version control to easily wipe our all of the generated classes after you have copied them to the Slim project. I might actually do that myself. :slight_smile:

That is very cool. How come I don’t know that. I was too focusing to solve the problem. I totally agreed with use a Laravel as a temporary generator tool, totally makes sense. Thanks.

I have been thinking about this for awhile now, but because Slim project structure is different per developer/per project, there is no easy way of doing something like this. Also a copy and paste is probably as quick as a generator, so I would suggest you create a GenericController file somewhere that you copy each time you need to create a new Controller.

I’ve created a personal super simple custom CLI to create Eloquent model classes for my projects. This is basically a step above of copy/paste in where it replaces strings in a template file with arguments in the command to generate a new file.

I have a github repo as an example. It’s quite primitive but it does make the bootstrapping a little quicker if your project needs several model classes.

Thank you, Robro. I had tried it, it is not same as the original one.