erdemozveren/laravelmacros is a Laravel package for laravel helper macros for your project.
It currently has 0 GitHub stars and 4 downloads on Packagist (latest version v0.3.2).
Install it with composer require erdemozveren/laravelmacros.
Discover more Laravel packages by erdemozveren
or browse all Laravel packages to compare alternatives.
Last updated
I'm lazy,so i made package with some handful shourtcuts for Laravel.
Compatibility:Laravel 5.8+ , Not stable for production
Via Composer
$ composer require erdemozveren/laravelmacros
For customization, first publish config file
$ php artisan vendor:publish --provider="erdemozveren\laravelmacros\LaravelMacrosServiceProvider" --tag=config
Now you can edit default configuration for inputs,settings etc.
laravelmacros aims to build simple skeleton for forms and form proccess easy
To getting started add in your model use erdemozveren\laravelmacros\Traits\FormBuilderTrait; then in class use it as trait use FormBuilderTrait; now you ready to continue!
this package add Laravel collective macros to get things easier,you can use it by just simply add "c" to start and Upper case next letter,like this;
Form::text('email', '[email protected]') --> Form::cText('email', '[email protected]')
add formFields function to model
public function formFields() {
return [
"*"=>[ // wildcard will be applied to all elements
"options"=>
["style"=>"color:red!important"]
],
"parent_id"=>[ // "parent_id" is the name attribute
"type"=>"select", // input type (e.g. "select" will look for "cSelect")
"label"=>"Parent", // label text
"data"=>User::pluck('full_name','id'), // [ONLY FOR select] you can write any data source that laravel collective accepts
"options"=>[ // optional
"required"=>false // optional make input optional
// ... and other "laravel collective" options and dom parameters can be used in here
]
],
"full_name"=>[
"type"=>"text",
"label"=>"Full Name",
],
"email"=>[
"type"=>"text",
"label"=>"E-mail",
],
"password"=>[
"type"=>"password",
"label"=>"Password",
],
];
}
In your blade file you can use like this
{!!Form::model($model,['url'=>"/post"])!!}
{!!$model->generateForm()!!}
{!!Form::cSubmit()!!}
{!!Form::close()!!}
or
{!!Form::open(['url'=>"/post"])!!}
{!!$model->generateForm()!!}
{!!Form::cSubmit()!!}
{!!Form::close()!!}
if you want to exclude one or more elements in one form just pass option _exclude with array of fields name
{!!$model->generateForm(["_exclude"=>["full_name","another_filed_name"]])!!}
$ php artisan laravelmacros:formfields {tablename}
it will ask you some questions then give you formFields function code to copy into model file

These macros extended from laravel collective and can be used in model binding too.
Value of the input will be (in order) ;
Request::input method)// variable names stand for paramaters with default values
Form::cText($name,$label,$placeholder=null,$options=[]);
Form::cColor($name,$label,$options=[]);
Form::cTextarea($name,$label,$placeholder=null,$options=[]);
Form::cNumber($name,$label,$options=[]);
Form::cEmail($name,$label,$placeholder=null,$options=[]);
Form::cPassword($name,$label,$placeholder="*******",$options=[]);
Form::cFile($name,$label,$options=[]);
Form::cCheckbox($name,$label,$value=1,$checked=null);
Form::cRadio($name,$label,$value,$checked=null);
Form::cSubmit($label="Submit",$class="");
Form::cSelect($name,$label,$data,$options=[]);
Please see the changelog for more information on what has changed recently.
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email author email instead of using the issue tracker.
MIT