ministrare/laravel-core-package

该包最新版本(v0.0.2-alpha)没有可用的许可证信息。

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:HTML

类型:

v0.0.2-alpha 2020-02-22 14:15 UTC

This package is auto-updated.

Last update: 2024-09-24 00:24:44 UTC


README

这个laravel核心包包含我为laravel 5.8编写的个人工具。
它包含以下内容

表单

Form类由一个门面支持,允许静态访问所有函数。Form类包含3个主要元素

方法

示例用法

<?= Form::Method('POST', route('login')) ?>

'Method'函数会输出带有@csrf元素的HTML表单元素。
该函数需要2个参数:```POST|GET```,```Route```。

输入

示例

<?= Form::Input('type', 'label (optional)', 'slug (optional)', ['options (optional)'])->Render() ?>

Form::Input函数创建一个HTML表单输入字段。
该函数至少需要1个参数:类型。
其他参数,如:字符串label,字符串```slug```和数组```options```是可选的。
可能类型选项

输入类型

复选框

!仍在开发中!

<?= Form::Input('checkbox', __('label'), 'slug', [
    //Required
    'options' => [
        'value_checkbox_option_1' => '(string) label checkbox option 1',
        'value_checkbox_option_2' => '(string) label checkbox option 2',
    ],
    // optional
    'class' => '(string) If set, sets the HTML property class with given value.',
    'message' => '(string) If set, sets and show the error message.',
    'value' => "(string) if set, sets the checkbox that matches the giving key value",
])->Render() ?>

示例用法

<?= Form::Input('checkbox', __('Remember Me'), 'remember', [
    'class' => 'col-md-8 offset-md-2',
    'options' => [
        'remember' => __('Remember Me'),
    ],
    'message' => isset($message) ? $message : '',
    'value' => $checkbox,
])->Render() ?>

电子邮件

<?= Form::Input('email', __('label'), 'slug', [    
    // optional
    'autocomplete' => '(boolean) If set, sets the HTML property autocomplete with the slug.',
    'autofocus' => '(boolean) If set, sets the HTML property autofocus.',
    'class' => '(string) If set, sets the HTML property class with given value.',
    'icon' => '(string) If set, shows a font-awesome 4.7.0 icon instead of the label. example: "address-book" will result in "fa fa-address-book".',        
    'message' => '(string) If set, sets and show the error message.',
    'placeholder' => '(string) If set, sets the HTML property placeholder with given value.',
    'required'=> '(boolean) If set, sets the HTML property required.',
    'small' => '(string) If set, sets the footnote text of the email input field.',
    'value' => "(string) if set, sets the HTML property value with giving string value",
])->Render() ?>

示例用法

<?= Form::Input('email', __('E-mail'), 'email', [
    'placeholder' => 'example@website.com',
    'class' => 'col-md-8 offset-md-2',
    'required'=> true,
    'autofocus' => true,
    'message' => isset($message) ? $message : '',
    'value' => $email,
])->Render() ?>

密码

<?= Form::Input('password', __('label'), 'slug', [    
    // optional
    'autocomplete' => '(boolean) If set, sets the HTML property autocomplete with the slug.',
    'autofocus' => '(boolean) If set, sets the HTML property autofocus.',
    'class' => '(string) If set, sets the HTML property class with given value.',
    'icon' => '(string) If set, shows a font-awesome 4.7.0 icon instead of the label. example: "address-book" will result in "fa fa-address-book".',        
    'message' => '(string) If set, sets and show the error message.',
    'placeholder' => '(string) If set, sets the HTML property placeholder with given value.',
    'required'=> '(boolean) If set, sets the HTML property required.',
    'small' => '(string) If set, sets the footnote text of the email input field.',
    'value' => "(string) if set, sets the HTML property value with giving string value",
])->Render() ?>

示例用法

<?= Form::Input('password', __('Password'), 'password', [
    'class' => 'col-md-8 offset-md-2',
    'message' => isset($message) ? $message : '',
    'value' =>  '',
])->Render() ?>

单选按钮

<?= Form::Input('radio', __('label'), 'slug', [
    //Required
    'options' => [
        'value_radio_option_1' => '(string) label radio option 1',
        'value_radio_option_2' => '(string) label radio option 2',
    ],
    // optional
    'class' => '(string) If set, sets the HTML property class with given value.',
    'message' => '(string) If set, sets and show the error message.',
    'value' => "(string) if set, sets the radio option that matches the giving key value",
])->Render() ?>

示例用法

<?= Form::Input('radio', __('Remember Me'), 'remember', [
    'class' => 'col-md-8 offset-md-2',
    'options' => [
        0 => __('Remember Me'),
        1 => __('Don`t Remember Me'),
    ],
    'message' => isset($message) ? $message : '',
    'value' =>  '',
])->Render() ?>

选择

<?= Form::Input('select', __('label'), 'slug', [
    //Required
    'options' => [
        'value_radio_option_1' => '(string) label radio option 1',
        'value_radio_option_2' => '(string) label radio option 2',
    ],
    // optional
    'class' => '(string) If set, sets the HTML property class with given value.',
    'emptyFirst' => "(string) If set, places a empty option in front of the options to display e empty field on load",
    'message' => '(string) If set, sets and show the error message.',
    'multiple' => '(boolean) if set, allows the user to select multiple options.',
    'value' => "(mixed) if set with value_radio_option, will select this option on load. For multiple select, array value allowed."
])->Render() ?>

示例用法

<?= Form::Input('select', __('Roles'), 'roles', [
    'class' => 'col-md-8 offset-md-2',
    'emptyFirst' => true,
    'options' => [
        1 =>'test',
        2 =>'Administrator',
        3 =>'Administrator',
        4 =>'Administrator',
    ],
    'value' => 2,
])->Render(); ?>

<?= Form::Input('select', __('Roles'), 'roles', [
    'class' => 'col-md-8 offset-md-2',
    'multiple' => true, // Multiple selector
    'options' => [
        1 =>'test',
        2 =>'Administrator',
        3 =>'Administrator',
        4 =>'Administrator',
    ],
    'value' => [1,4],   // Multiple values given true array
])->Render(); ?>

字符串

<?= Form::Input('string', __('label'), 'slug', [    
    // optional
    'autocomplete' => '(boolean) If set, sets the HTML property autocomplete with the slug.',
    'autofocus' => '(boolean) If set, sets the HTML property autofocus.',
    'class' => '(string) If set, sets the HTML property class with given value.',
    'icon' => '(string) If set, shows a font-awesome 4.7.0 icon instead of the label. example: "address-book" will result in "fa fa-address-book".',        
    'message' => '(string) If set, sets and show the error message.',
    'placeholder' => '(string) If set, sets the HTML property placeholder with given value.',
    'required'=> '(boolean) If set, sets the HTML property required.',
    'small' => '(string) If set, sets the footnote text of the email input field.',
    'value' => "(string) if set, sets the HTML property value with giving string value",
])->Render() ?>

示例用法

<?= Form::Input('string', __('First name'), 'first_name', [    
    'placeholder' => 'First name',
    'class' => 'col-md-8 offset-md-2',
    'required'=> true,
    'autofocus' => true,
    'message' => isset($message) ? $message : '',
    'value' => $first_name,
])->Render() ?>

文本框

<?= Form::Input('textarea', __('label'), 'slug', [
    // optional
    'class' => '(string) If set, sets the HTML property class with given value.',
    'rows' => "(integer) If set, sets the HTML property rows with given value",
    'value' => '(mixed) If set, sets the textarea with given value',
])->Render() ?>

示例用法

<?= Form::Input('textarea', __('Message'), 'message', [
    'class' => 'col-md-8 offset-md-2',
    'rows' => 3,
    'value' => $message,
])->Render() ?>

链式函数

大多数参数可以在首次设置后被覆盖。这是通过链式多个设置函数实现的。
这允许通过覆盖最重要的参数在它们自己的设置函数中轻松使用/覆盖。所有设置函数如下所示,按正确顺序排列

<?= Form::Input(string)->Label(string)->Slug(string)->Options(array)->Render(); ?>    

渲染

Form::Input('type')->Render()函数允许将所有给定选项解析到视图中。如果没有Render()函数,则不会加载Form::Input视图,因此这是一个重要函数,在链中。

结束

示例用法

<?= Form::End() ?>

End函数输出HTML表单结束标签。
该函数没有参数。

返回顶部

工具

Utilities类由一个门面支持,允许静态访问所有函数。Utilities类包含2个主要元素

createSlug

slug是一个HTML/mysql友好的字符串。示例用法

<?= Utilities::createSlug(string $name) ?>

它会删除不需要的空格,并用下划线(_)替换它们。这个函数用于创建用于HTML输入元素名称参数的slug。

keyExists

示例用法

<?= Utilities::keyExists(string $needle, array $haystack) ?>

一个在数组中查找键并返回键的函数。

返回顶部