bpocallaghan / generators Goto Github PK
View Code? Open in Web Editor NEWLaravel File Generators with config and publishable stubs
License: MIT License
Laravel File Generators with config and publishable stubs
License: MIT License
Hi,
I was thinking about what you've done here.You know that message that says
.somepath/some/test.bladee.php Was generated
At the end.I guess it could be great if in config/generator.php
A function could be defined to handle that message.
You may think what kind of stupid feature is that :D
But the purpose is that you can do a few stuff here to open the files that were generated in the ide.
Since I think it isn't such a great idea to handle all these ide opening stuff yourself because I see you're working alone on this, I guess that would be a lot better so you can do a few ones and let the rest of it to the other ide users.
There are two possible ways to open a file in ide from php.
Either output a link like idea://blahblah...
Which is a link that when opens gets you there.
Or some ideas again like intellij suppert a command for opening files in terminal so a exec() in php could do that or again intellij can open files in this link too : file:///path.blade.php
So you get the point,that could let the users do any of these ways in their ides which I think is a great idea.
The other thing you said generate::request
I don't know what that is but in a few days I'm making something which basically makes adding somethings like routes in web.php automated from php well essentially I'm doing it for some other reason, but if that's something like what you need, I'll provide the code to what I've done when it's done and also can help you adapt it for your own use case.It's just a little playing with regex. But I guess you won't need my help. Anyways it never hurts to hear somebody offers some help.
When we use this command and inject the many to many relationship in the model, the classes are inverted.
Example
generate:migration:pivot bar foo
would currently add in the Foo Class Model
public function bars()
{
return $this->belongsToMany(Foo::class);
}
I believe it should be
public function bars()
{
return $this->belongsToMany(Bar::class);
}
Add a protected function for the placeholders used in the build method.
So that each generate command uses the same logic to generate placeholders, and each generate command has access to all the placeholders available.
Use the abstract buildClass method (issue 2)
Maybe remove the duplicate of the view commands (index / show / add_edit)
In {{schema_up}}...{{resource_name}} is not pulling in and shows up as "{{resource_name}}" so if we have a resource of foo_bars...in my stub for the migration we have
$table->string('{{resource_name}}_name');
It would be nice to have it come in as
$table->string('foo_bar_name');
MigrationCommand - use the base FileCommand - to get access to all the 'placeholders' to replace in the stub.
Would it be possible to also add stubs for repositories and contracts?
Our project is growing and it would be nice to stub out this when we use generate:resource foo and maybe add flags to include a repository and contract?
What do you think?
We also came across the quasar framework
Totally Vue..pretty nice...thought I would share.
Using this command :
php artisan generate:model bar --migration --plain
It created a migration with this up method :
public function up()
{
Schema::create('bars', function (Blueprint $table) {
$table->bigIncrements('id')->unique()->index();
$table->timestamps();
$table->softDeletes();
$table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned()->nullable();
$table->integer('deleted_by')->unsigned()->nullable();
});
}
I don't want these auto generated fields from out of nowhere to come they were not in the stub file as well.
Maybe add a FileCommand that will take a --stub option for the name of the stub to use from the config file.
So that you will be able to generate any file you add in the config file.
Generate any custom files, that will be able to use all the placeholders available.
Love the package...using it daily.
However, in using:
generate:resource example_resource
In the controller section, it is not consistent with the others like view, model, etc...
It changes the {{resource_name}} to {{resourceName}}
I commented out the code here:
private function callController()
{
$name = $this->getResourceControllerName();
if ($this->confirm("Create a controller ($name) for the $this->resource resource? [yes|no]")) {
$arg = $this->getArgumentResource();
$name = substr_replace($arg, str_plural($this->resource), strrpos($arg, $this->resource), strlen($this->resource));
// foo.bar_baz == foo.barBaz
//$pieces = explode('_', $name);
//$name = "";
//foreach ($pieces as $k => $str) {
// $name .= ucfirst($str);
//}
$this->callCommandFile('controller', $name);
}
}
Now works as expected, unless I am missing why we would go fooBar instead of foo_bar when we use:
php artisan generate:resource foo_bar
Of course the model being FooBar is understandable...but when we call {{resource_name}} in the other sections...it gives foo_bar as expected.
Thanks for the hard work!
Erik
I can't publish the config file using php artisan vendor:publish
, nor does it publish the stubs. Is there specific way of doing this, or will you implement the publishes()
method in the service provider to automatically export them?
Thanks
Hello,
I just noted this issue, you might be aware but still just mentioning here.
Class ListenerCommand, FileCommand which use the 'DetectsApplicationNamespace' trait which is present only after 5.4. So please either add minimum Laravel version in a composer.json & readme.md or use AppNamespaceDetectorTrait for an older version.
Thanks.
Hey Ben-Piet!
It's been awhile, I saw the update so I ran it...
However, if stubs are already published, they need to be published again with --force in order for them to be used...I just cleaned in git all my existing stubs, then it worked...
Hi how do I use the shortcuts defined in the docs?
Not an issue, but would be helpful.
During this process would it make sense to automatically establish the many-to-many relationship between foo and bar put
In the Bar model:
public function foos() {
return $this->(Belongs to many stuff here with the 4 parameters)
}
In the Foo model
public function bars(){
return $this->belongsToMany( inverse of above not needing the 4 parameters??)
}
Thoughts?
Ex:
When I run the generate:migration:pivot foos bars
The migration created is created as:
class extends Migration
{
(missing the name)
I believe it should be
class CreateFooBarPivotTable extends Migration
{
I don't see that this function is being called anywhere during the pivot migration
protected function parseName($name)
{
$tables = array_map('str_singular', $this->getSortedTableNames());
$name = implode('', array_map('ucwords', $tables));
return "Create{$name}PivotTable";
}
From the:
public function fire()
{
$name = $this->qualifyClass($this->getNameInput());
......
It looks like it is calling only
/**
* Empty 'name' argument
*
* @return string
*/
protected function getNameInput()
{
//
}
Which of course will return an empty name
In the meantime, I'll just type that in
Thanks
Hi,
It looks like this package is locked to PHP 7:
- bpocallaghan/generators is locked to version 7.0.1 and an update of this package was not requested.
- bpocallaghan/generators 7.0.1 requires php ^7.3 -> your php version (8.0.3) does not satisfy that requirement.
Validator idea...
Also, I never run the migration at the time of generate:resource since there are only a few things that are common, the rest gets built, then the migration is performed. Once performed, it would be great to do some like:
generate:validator foo_bar
And then using Doctrine/dbal we could get the schema and inject the proper validator in the store and update of the FooBarController (at least all of the required fields.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.