8.1Laravel Collective之HTML

laravelcollective/html不仅仅提供了Form,还提供了其他HTML方面的功能。

安装

composer require laravelcollective/html

使用方式

//{!!........!!}
{!! Form::open() !!}
    //
{!! Form::close() !!}
//<?php........?>
<?php echo Form::open() ?>
    //
{?php Form::close() ?>

CSRF

如果使用POSTPUT or DELETE方法,CSRF会被自动添加。

Form::token()

添加CSRF过滤器到路由

Route::post('profile',
    [
        'before' => 'csrf',
        function()
        {
            //
        }
    ]
);

Model

{!! Form::model($user, ['route' => ['user.update', $user->id]]) !!}
{!! Form::close() !!}

Label

Form::label('email', 'E-Mail Address')

Text

Form::text('username', 'Username')

TextArea

Form::textarea('body')

Password

Form::password('password', ['class' => 'awesome'])

Email

Form::email($name, $value = null, $attributes = [])

File

Form::file($name, $attributes = [])

Checkbox

Form::checkbox('name', 'value')

Radio

Form::radio('name', 'value')

Number

Form::number('name', 'value')

Date

Form::date('name', \Carbon\Carbon::now())

Select

Form::select('size', ['L' => 'Large', 'S' => 'Small'], 'S')
Form::select('size', ['L' => 'Large', 'S' => 'Small'], null, ['placeholder' => 'Pick a size...'])
Form::select('animal',[
    'Cats' => ['leopard' => 'Leopard'],
    'Dogs' => ['spaniel' => 'Spaniel'],
])
Form::selectRange('number', 10, 20)
Form::selectMonth('month')

Submit

Form::submit('Click Me!')

URL

link_to

Generate a HTML link to the given URL.

link_to('foo/bar', $title = null, $attributes = [], $secure = null)

link_to_asset

Generate a HTML link to the given asset.

link_to_asset('foo/bar.zip', $title = null, $attributes = [], $secure = null)

link_to_route

Generate a HTML link to the given named route.

echo link_to_route('route.name', $title = null, $parameters = [], $attributes = [])

link_to_action

Generate a HTML link to the given controller action.

link_to_action('HomeController@getIndex', $title = null, $parameters = [], $attributes = [])

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/laravel/6689.html

发表评论

登录后才能评论