传递给App \ Http \ Controllers \ ProfileController :: store()的参数2必须是App \ Http \ Requests \ CreateProfileRequest的实例,未给出任何实例

Shebs72

我已经将我的头发拉出这个错误已有几个小时了,但不知道为什么会这样做。我之前在Laravel上完成过此操作,但似乎并不想工作。

这是我试图开始工作的方法:

public function store($name, CreateProfileRequest $request)
{
    $user = User::whereName($name)->first();


    $house = new House();
    $house->first_line_address = $request->get('first_line_address');
    $house->city = $request->get('city');
    $house->postcode = $request->get('postcode');

    $user->house()->save($house);

    return redirect('/');

}

这是我试图从中获取数据的表格:

{!! Form::model($user->house, ['route' => 'profile.store']) !!}

    <div class ="form-group">
        {!! Form::label('first_line_address', 'First line of address:') !!}
        {!! Form::text('first_line_address', null, ['class' => 'form-control'])!!}
    </div>

    <div class ="form-group">
        {!! Form::label('city', 'Town/City:') !!}
        {!! Form::text('city', null, ['class' => 'form-control'])!!}
    </div>

    <div class ="form-group">
        {!! Form::label('postcode', 'Postcode:') !!}
        {!! Form::text('postcode', null, ['class' => 'form-control'])!!}
    </div>

    <div class ="form-group">
        {!! Form::submit('Update Profile', ['class' => 'btn btn-primary']) !!}
    </div>

    {!! Form::close() !!}
</div>

没关系,直到我尝试存储它,然后我得到

传递给App \ Http \ Controllers \ ProfileController :: store()的参数2必须是App \ Http \ Requests \ CreateProfileRequest的实例,未给出任何实例

这是我的路线:

$router->resource('profile', 'ProfileController');

| GET | HEAD | 个人资料 profile.index | App \ Http \ Controllers \ ProfileController @ index | |

| | GET | HEAD | 个人资料/创建| profile.create | App \ Http \ Controllers \ ProfileController @ create | |

| | 发布| 个人资料 profile.store | App \ Http \ Controllers \ ProfileController @ store | |

| | GET | HEAD | 个人资料/ {profile} | profile.show | App \ Http \ Controllers \ ProfileController @ show | |

| | GET | HEAD | 个人资料/ {profile} / edit | profile.edit | App \ Http \ Controllers \ ProfileController @ edit | |

| | 放置| 个人资料/ {profile} | profile.update | App \ Http \ Controllers \ ProfileController @ update | |

| | 补丁| 个人资料/ {profile} | | App \ Http \ Controllers \ ProfileController @ update | |

| | 删除 个人资料/ {profile} | profile.destroy | App \ Http \ Controllers \ ProfileController @ destroy | |

如果有人想到如何摆脱这个荒谬的错误,我将永远感激:)

Lukasgeiter

store()资源控制器/路由方法不采用任何路由参数。这意味着Laravel没有什么可作为$name论点。我想您是在请求数据本身中传递名称。如果是这种情况,您可以使用进行访问$request->input('name')

无论如何,您应该$name从方法签名中删除

public function store(CreateProfileRequest $request)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档