erdemozveren/laravelmacros 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

erdemozveren/laravelmacros

Composer 安装命令:

composer require erdemozveren/laravelmacros

包简介

Laravel helper macros for your project

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

I'm lazy,so i made package with some handful shourtcuts for Laravel.

Compatibility:Laravel 5.8+ , Not stable for production

Usage

Installation

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.

Getting Started

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', 'example@gmail.com') --> Form::cText('email', 'example@gmail.com')

Usage

Form Builder

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",
        ],
    ];
}

Generate Form

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"]])!!}

Auto generate form fields

$ php artisan laravelmacros:formfields {tablename}

it will ask you some questions then give you formFields function code to copy into model file

Form Macros

These macros extended from laravel collective and can be used in model binding too.

Value of the input will be (in order) ;

  1. Session Flash Data (Old Input)
  2. Data From Current Request (via Request::input method)
  3. Explicitly Passed Value
  4. Model Attribute Data
// 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=[]);

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

MIT

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固