Download the PHP package skyronic/laravel-file-generator without Composer
On this page you can find all versions of the php package skyronic/laravel-file-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-file-generator
Laravel file generator
This is a Laravel package which helps you automate creation of files.
Benefits
- If you create a type of file frequently, you can automate it and improve productivity.
- Prevent "context switching" where you lose focus for 30 seconds while you create new files, directories and populate it with boilerplate.
- Comes with several built-in boilerplates. Easy to share your own as github gists.
- All boilerplates and generators are part of your repository, letting you share standard templates with your team.
- Find things like
artisan make:model
andartisan make:controller
useful? You can make your own. - All boilerplates can be written as blade templates.
Quick Start
Step 1: Install the package
Step 2: Publish the "boilerplates" - an included set of useful boilerplates like PHP Classes.
Step 3: You can list all the installed boilerplates
Step 5: You can create a php class now:
The generator php:class
creates one by default in. You can now open app/Support/Helpers/AwesomeHelper.php
Step 6: Create your own template:
Understanding Boilerplate Template
Open the file created by Step 6. You will see something like this:
There's two parts to the file, separated by ---
.
- The top part is the configuration of how the template should behave, and also specifying parameters
- The bottom part is the actual template which will be.
The configuration object
Let's take a closer look at this config object:
This should be valid JSON. The key name
is the name of the template used for generate:list
. Not to be confusued with the $name
variable.
Setting Output Path
If you try to run the template with something like:
The output path here will be: edit/me/foo/bar.txt
. $name
contains the second parameter, and even the strings can use blade so {{ $name }}
will produce the path.
Parameters
Parameters allow you to customize and change the content of the file. For example, here we have myParam
. So running this boilerplate with
Will result in the text file:
Flag Parameters
Here's a simple template (some elements omitted for brevity).
Now we can run it like:
Required Parameters
Optional Parameters
You can recognize the if
and endif
as blade conditional structures. If authorName
is set like:
Then the value is set to "John". Else it's null.
Default Values
If you set the parameter to anything except flag
or optional
or required
it's considered a default value.
The value is going to be set to 2017 unless specified otherwise.
Tips for writing boilerplates
- A template like
vue__component.boilerplate.txt
will becomevue:component
for cleaner organization. You can use__
in your own templates. - Important: Pass a
--dry-run
flag likephp artisan generate --dry-run mytemplate foo/bar --myParam "paramvalue"
to display the output in console. This lets you iterate and fix any potential issues without creating files. - You can use most of laravel's helper functions and even some other PHP classes with some advanced blade and the
@php
directive - You can use paths like
foo/bar/{{ $name }}
and FileGenerator will automatically adjust directory separators on windows.
If you're using this tool to generate blade files, using keywords like @section
and @extends
might not work. Instead use @@section
and @@extends
For example:
Formatter
Sometimes you might need to do some string manipulation. Later versions of File Generator will contain more comprehensive string manipulation later.
Camel-case, Snake-case, etc
You can use Laravel's built in helpers for things like camel_case and others.
Basename from path
If you've got something like app/Support/MyHelper.php
and want to extract MyHelper
you can use Format::baseName ($path)
which extracts a classname like entity, ignoring any file extension.
Getting a namespace from path
Namespaces are a bit tricky, since they need to render forward-slashes. FileGenerator contains a simple format helper which can generate a namespace from a given file path. It uses the laravel app
directory and App
namespace by default.
Example: PHP Class generator
First, be sure that you've run php artisan vendor:publish --tag='boilerplates'
and check app/resources/boilerplates/php__class.boilerplate.txt
The example should be pretty self explanatory. But can illustrate that even a little blade templating can go a long way.
All versions of laravel-file-generator with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
illuminate/console Version ^8.0|^9.0|^10.0|^11.0
illuminate/view Version ^8.0|^9.0|^10.0|^11.0
illuminate/filesystem Version ^8.0|^9.0|^10.0|^11.0
symfony/finder Version ^6.0|^7.0