In Laravel, I can create models and controllers automatically from the command line using
artisan
However, There is no command to generate views automatically based on the the model for CRUD operations. Wonder if there is a tool that would make this out of the box. I imagine this:
php artisan make:view model
and then I have all my views ready. I tried to search online but could not find a proper tool: LarvelCodeGenerator, and others...
Have you taken a look at Laravel View Generator.
Related
I am using Laravel Framework 6.20.44, which I can tell from php artisan -V
It comes part of OctoberCMS, which I just updated.
I'm jealous because the documentation for Laravel 6.x, and some many other resources, show that php artisan come with a make command, derived into so many subcommands.
I would like to enjoy a command like php artisan make:controller API/TopicController --api.
I can't, because my version of artisan returns:
Command "make:controller" is not defined.
Did you mean one of these?
create:controller
make:migration
It looks like I have an older version of artisan, heavily coupled to October.
I say coupled because I can spot commands such as october: when I list available artisan commands.
No luck with create:controller either, as --api is not implemented in my version...
My question: how do I update artisan so that I have access to the make command, according to the doco?
October CMS is developed in Laravel and it's not framework. It is CMS.
So, being CMS it has to maintain its directory structure with predefined paths. CMS is driven by plugins and themes. So you can only add/modify plugins or theme files.
So now if you try to add a controller where do it will add? it cants add to its system files OR in app/controllers/. To prevent this the authors of CMS have removed/overrideLaravel native commands to avoid creating the unexpected directory structure or files in core folders.
So basically you need to follow CMS rules and its command to maintain the directory structure and file structure of CMS. It's important otherwise CMS will not work.
php artisan create:controller <Author>:<PluginName> <ControllerName>
this is the exact definition: Create the controller in this plugin by this name. So it can work with CMS core logic.
Check some tutorials to understand how October CMS works:
How to install OctoberCMS
themes
How to edit OctoberCMS
themes
How to install OctoberCMS
plugins
Essential Plugins for
OctoberCMS
If any doubts please comment.
I have such following Database Schema that I want to convert into Lumen API with migration, model and API. Since I am new to Lumen Laravel Framework so need experts help:
Lumen is the light weight stripped version of Laravel, that is why I rever to the Laravel documentation in this answer.
First step is to write migration files, see:
https://laravel.com/docs/8.x/migrations
after creating the migrations files you can migrate the schemas with:
php artisan migrate
The next step is to create models for the tables, see:
https://laravel.com/docs/8.x/eloquent#generating-model-classes
This is necessary to query the data from the database with Eloquent (ORM in Laravel).
The two steps above can be combined with the command:
php artisan make:model ModalName --migration
The next step is to create a controller, this class will be used as a layer between your view/api and the data models, see:
https://laravel.com/docs/8.x/controllers
Last step: After creating your logic, you can register the controller in your api routes file, see:
https://laravel.com/docs/8.x/routing
The routes file you are looking for is called: api.php
If the ORM isn't what you are looking for then you can also use the query builder:
https://lumen.laravel.com/docs/8.x/database
I'm new to laravel backpack so what did is created a CRUD of title and description. And everything in admin panel works fine, but now I need to get that data to another blade view file through a controller like in a vanilla laravel but I cant seem to find how to do it.
If I understand your question correctly, there's absolutely NOTHING special you need to do - just do it "the normal Laravel way", by using your Model to query the database. It's usually something like Career::all() or Career::find($id) or Career::where('something', $value)->get(), depending on what you need to fetch from the database.
That's because Backpack uses your existing Eloquent Models, or creates the models if you don't have them already (usually in app\Models). So whenever you create/edit/delete an entry using the Backpack interface (aka CRUD), what Backpack does is use that Model to interact with the database. If you want to interact with the database, you should do the same thing - use the Model. That's the expected and recommended way of doing things in Laravel. To have Models for all your major database tables and do most (or all) of your interactions with the database using the Eloquent Models.
You can use view like this:
view('crud::show');
list, create etc.
all available files, you can find here: vendor/backpack/crud/src/resources/views/crud
If you want to override the template, please copy vendor template to your project
vendor/backpack/crud/src/resources/views/crud/show.blade.php > resources/views/vendor/backpack/crud/show.blade.php
I found laravel very interesting. But I'm wondering if there's any artisan command to generate all MVC skeleton files provided a database table all at ones. And how about separate generation of especially the model, given the table structure? or is there any alternative way to do the code generating?
You can create a migration file from the table via the package below.
https://github.com/Xethron/migrations-generator
Install it via : composer require --dev "xethron/migrations-generator"
Follow the package instructions, After connecting you application with the database simply run php artisan migrate:generate.
You will see number of migrations created via console message, You can also check your database/migrations folder for confirmation.
I didn't find how to do that, so I created my own code in order to create the models:
https://github.com/Triun/laravel-model-base
It is not super documented, but you can actually write your own addons in order to add custom business behaviors or include your own interfaces or traits to your models, with your own code.
And of course, reports and contributions are more than welcome.
I hope this helps.
Rails generates a folder of view template scaffolds when you run the cli command rails g controller User.
It will have view template scaffolding for create_user.html.erb, update_user.html.erb, list_user.html.erv....etc etc.
Is there anyway to have that same functionality in Laravel whether via a library, some included function, or a custom generator(or some other way)?
I'm using Laravel 5.4 if that makes a difference.
Since you're looking to generate views, I assume you're talking about a CRUD admin panel rather than an API. I highly recommend Laravel CRUD.
https://github.com/Laravel-Backpack/CRUD
This will allow you to create a model, controller, all routes, views etc with the command php artisan backpack:crud Model. It's super easy to use, but you'd want to probably start your project fresh - it assumes you're using it for the whole admin section, not just the views.