如何在Laravel中使用表单模型绑定改变动作?


How do you change the action with Form Model Binding in Laravel?

我有一个简单的模型绑定表单,并且刚刚检查了由刀片生成的html,并且该动作指向错误的url。我把路线写错了吗?没有任何文档对此有所帮助。动作指向/users,而不是路由指向的/users/{user}。

@extends('layout')

@section('content')
    <h1>This is a test.</h1>
    <ul>
        @foreach($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
    {!! Form::model($user, ['method'=>'put', 'route'=>['users.update', $user->id], 'class'=>'form']) !!}
    <div class="form-group">
         {{ csrf_field() }}
        {!! Form::label('Your Name') !!}
        {!! Form::text('name', null, 
            ['required', 'class' => 'form-control', 'placeholder'=>'Your name']
        ) !!}
    </div>
    <div class="form-group">
        {!! Form::label('Your E-mail Address') !!}
        {!! Form::text('email', null, 
            ['required', 'class' => 'form-control', 'placeholder'=>'Your E-mail Address']
        ) !!}
    </div>
    <div class="form-group">
        {!! Form::submit('Submit', ['class'=>'btn btn-primary']) !!}
    </div>
    {!! Form::close() !!}
@stop

可以在这里找到路由打印输出:http://pastebin.com/4wpMsz4k

试试下面这个,

{!! Form::model($user, array('route' => array('users.update', $user->id), 'method' => 'PUT','class' => 'form')) !!}

问题解决。这是一个id格式不正确的问题。它应该是$user->ID,而不是$user->ID。