Create a Resource Controller? - laravel

I'm trying to make a resource controller in my package but i'm not sure how to do it.
Normally I would use:
php artisan controller:make MyController
But how can I make it so this is created in my package?

If you take a look at php artisan help controller:make you will see that there is a path option, so I guess that's what you're looking for.
Another option would be to explore the workbench which will make things easier while developing a package

Related

php artisan make:controller is not defined

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.

Should I copy controller, or use artisan:make controller?

I have this great doubt, if I copy and modify an existing controller in my laravel project vs create a controller with php artisan make:controller MyController, Is there any affected configuration files? or is it normal to copy and edit my other controllers?
It's just a lot easier to do the official command
php artisan make:controller myController
I mean, it's what they are there for. I don't believe that hand-making a controller will have a negative effect but it's so much easier and safe to use the function that's already defined.
many times in a controller you have a lot of logic that you want to reuse, IMHO sometimes it's worth manually copying the controller.

Can Laravel generate all mvc skeleton out of an existing table like that of cakephp's command cake bake all

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.

Check config/assets are published or not in Laravel package

I have two questions which are quite related.
1) I'm building a Laravel package which will have a package config file. It can be published using php artisan vendor:publish command. Now in the service provider class of that package, I want to know that if that file has been published by the user or not. How can I do that? By simply checking file existence or is there any Laravel specific way for that?
2) In the view file of that package, I want to include a js file which is also there in that same package. How can I do that? Do I have to publish it first into Laravel's public directory and then include it? If possible I don't want to publish it.
Let me know if anything is not clear.
Thanks

Can laravel create a view inside resources/views?

I have succesfully been able to create a file inside Storage / Public, but I am wondering if anyone knows if you can create a view inside resources/views with any laravel functions?
Currently there is no direct command to do this but you can use the package Artisan View. This package adds a couple of view-related commands to Artisan in your Laravel projects. You can try this : Artisan View

Resources