A Laravel File Generator to automate creation of interface, trait and class files.
timehunter/laravel-file-generator is a Laravel package for a laravel file generator to automate creation of interface, trait and class files..
It currently has 1 GitHub stars and 95 downloads on Packagist (latest version 1.8.0).
Install it with composer require timehunter/laravel-file-generator.
Discover more Laravel packages by timehunter
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel File Generator which allows you to:
The main logic is using Blade template engine to populate the files. Feel free to look into the source code.


This package requires the following dependencies:
Via Composer
$ composer require timehunter/laravel-file-generator "^1.8.0"
If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please skip it.
'providers'=[
....,
TimeHunter\LaravelFileGenerator\LaravelFileGeneratorServiceProvider::class
]
And also ( Laravel framework version <= 5.4)
'aliases'=[
....,
'LaravelFileGenerator' => TimeHunter\LaravelFileGenerator\Facades\LaravelFileGenerator::class
]
Create a file template in which you tell the generator what information will be appended to your file. e.g. the following is an example of Interface file template which implements InterfaceSimpleTemplateInterface:
<?php
namespace App\Structure;
use TimeHunter\LaravelFileGenerator\Interfaces\InterfaceSimpleTemplateInterface;
class ExampleSimpleInterfaceTemplate implements InterfaceSimpleTemplateInterface
{
public function getTemplateData()
{
return [
'directory' => app_path() . '/Example',
'interface_name' => 'ExampleInterface',
'namespace' => 'App\Example',
'functions' => [
'public function get()',
'public function update()'
],
'annotations'=[]
];
}
}
Pass the template to the publish function from LaravelFileGenerator facade class
LaravelFileGenerator::publish(
new ExampleSimpleInterfaceTemplate(),
new ExampleSimpleTraitTemplate(),
new ExampleSimpleInterfaceTemplate()
...
); // publish() supports multiple parameters
Check your folders if the file is generated.
You can also review the class before publishing:
return LaravelFileGenerator::preview(new ExampleSimpleInterfaceTemplate());
The function returns a View, so you can include it in any controller to see the outcome.
| Interface | Usage | Description | |----------------------------------|----------------------|----------------| | ClassSimpleTemplateInterface | array schema type | Class file | | InterfaceSimpleTemplateInterface | array schema type | Interface file | | TraitSimpleTemplateInterface | array schema type | Trait file |
For array schema type, they have the same function which returns schema of template:
getTemplateData()
public function getTemplateData()
{
return [
'directory' => app_path() . '/Example',
'namespace' => 'App\Example',
'use' => [
'App\Http\Controllers\Controller'
],
'trait_name' => 'ExampleTrait',
'traits' => [
'ExampleTrait'
],
'annotations'=[],
'functions' => [
'public function get()',
'public function update()'
]
];
}
public function getTemplateData()
{
return [
'directory' => app_path() . '/Test',
'interface_name' => 'ExampleInterface',
'namespace' => 'App\Example',
'annotations'=[],
'functions' => [
'public function get()',
'public function update()'
]
];
}
public function getTemplateData()
{
return [
'class_type' => 'abstract class',
'directory' => app_path() . '/Example',
'namespace' =>'App\Example',
'use' => [
'App\Http\Controllers\Controller',
],
'class_name' => 'ExampleClass',
'extends' => 'Controller',
'implements' => ['sss', 'sss'],
'traits' => [
'ExampleTrait'
],
'properties' => [
'protected $repo'
],
'functions' => [
'public function get()',
'public function update()'
],
'annotations'=[]
];
}
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.