我正在尝试查看我的编辑表单。但是它为更新路由提供了缺少路由的参数

问题描述 投票:1回答:1

这是我的代码。Editpost.blade.php

<form action="{{ route('update_post') }}" method="POST" enctype="multipart/form-data">
    @csrf
    <div class="container">
        <div class="header">
            <h1>Edit Post</h1>
            <p>Please fill in this form to update the post.</p>
        </div>
        <input type="hidden" name="id" value="{{ $post->id }} ">

        <label for="name"><b>Post Name</b></label>
        <input type="text" placeholder="Enter Post Name" name="name" value="{{ $post->name }}"><br><br>

        <label for="link"><b>Post Link</b></label>
        <input type="url" placeholder="Enter Link" name="url" value="{{ $post->url }}"><br><br>

        <label for="image"><b>Post Image</b></label>
        <input type="file" placeholder="Upload Image" name="image" value="{{ $post->image }}"><br><br>

        <input type="submit" value="submit">

        {{--
        <div class="clearfix">
            <button type="submit" class="cancelbtn">Sign Up</button>
            <button type="button" class="signupbtn">Sign In</button>
        </div>
        --}}
    </div>
</form>

web.php

route::get('admin/show-post/edit-post/{id}','MyController@edit_post')->name('edit_post');

route::post('admin/show-post/edit-post/update-post/{id}','MyController@update_post')->name('update_post');

发生此错误

Facade \ Ignition \ Exceptions \ ViewException缺少[Route:update_post] [URI:admin / show-post / edit-post / update-post / {id}]的必需参数。 (查看:C:\ wamp64 \ www \ portfolio \ resources \ views \ editpost.blade.php)http://localhost/portfolio/admin/show-post/edit-post/6

laravel-5
1个回答
1
投票
您必须修改表单操作,以传递要更新的ID

action="{{ route('update_post', ['id' => $post->id]) }}

© www.soinside.com 2019 - 2024. All rights reserved.