How to generate Laravel's Model, Model's Migration and Controller programmaticaly
So i want to generate Model then Model's migration programmatically. What I mean by that is; for instance I have a form that accepts model name and migration fields. I want to be able to submit form and let my Laravel code generate model and migration automatically. Also I want to be able to generate controller code based on some logic. Is it possible to achieve what I describe with Laravel and PHP?
@newbie360 how can I send data via artisan commands to stubs then? How can I edit the existing Model, Migration, and Controller code? Stubs are good but how can I generate those properly using Laravel and PHP?
@webrobert Why on earth do you want form submissions responsible for generating server-side code? Users should not be able to create files like this at all.
@martinbean I want to make something that's why. Of course, not everybody can access this stuff and it will be protected and stuff, at least I hope so.
@webrobert Sorry! Yeah, was meant to be directed to @yarkin. Typed reply on mobile and think your name just came up first. Sorry again!
I want to make something that's why. Of course, not everybody can access this stuff and it will be protected and stuff, at least I hope so.
@yarkin Artisan has commands for creating these things. You don’t want to be doing them through forms. If you’re creating files via HTTP requests then—ignoring the massive security risk—it also means these files aren’t going to be version-controlled if they’re just created on an ad hoc basis.
@yarkin I’m not sure you will find a code example anywhere that directly does what you want. But I did give you the answer. That beeeze code does make controllers and migrations with options. Aside from make a form and wiring it up for you. What else do you want?
@webrobert basically I want to edit the whole routes folder's content, register new migrations, models, controllers. Change application's configurations fully. But I will use third-party services to deploy the admin panel generator so that it will have its own file system. And also an ai analyzer that analyzes code for threats and security.
How to generate Laravel's Model, Model's Migration and Controller programmaticaly
You said we’re off topic. And you wanted s simple answer. I think you already got the best answer. Look at how breeze does it. Given the maker of the framework wrote it. He just happens to call it via a command.
Wire it up to a form and try it. Just don’t break the internet.
it's a crazy idea because none of the rest of the application is going to be able to use this model and controller because they don't know anything about them
next you will want a code syntax highlighting editor that can allow the user to write their own functions in these new controller, and then to add routes to the web.php etc etc
Do you really want to support something like this? What possible use case is there for something that has to be installed by the user as a package but then they have to go through a web front end to add their code?
@Snapey yes I want to support this. Besides, if everything goes as planned, it will not be free. You have a point but could you at least answer my question? Cause these replies gone out of context. I just want simple answers like 'You can create models like that', 'Introduce them to the application like that'. I want to achieve my goal yet I get 0 support nor answers.
models, look how artisan creates models. It does it by using stubs with placeholders. You can copy that approach or come up with your own. You are going to need the shell of a class with places where you can string replace things
alternately call artisan from within your code. This is covered in the docs
As for migrations, look at a migration file. It's just a php class. It uses Blueprint to create or edit tables. Easy enough to replicate in your own code