简体   繁体   中英

Routing error in laravel 5.2

There is a route:

Route::get('message/{id}/edit', ['uses' => 'HomeController@edit', 'as' => 'message.edit'])->where(['id' => '[0-9]+']);

Code in my HomeController:

public function edit($id) {
    $data = [
        'title' => 'page',
        'pagetitle' => 'page',
        'message' => Message::find($id)
    ];

    return view('pages.messages.edit', $data);
}

And a view:

@extends('index')
@section('content')
    {!! Form::open(['route' => 'message.edit']) !!}
         @include('_common._form')
    {!! Form::close() !!}
@stop

And I get this error:

ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: message.edit] [URI: message/{id}/edit]. (View: C:\OpenServer\domains\laravel\book\resources\views\pages\messages\edit.blade.php)

Where is the problem? I tried to remove form from code, it works well. So it means that something wrong with the form.

您需要传递一个ID,因为您的路线需要它。

它应如下所示:

{!! Form::open(['route' => ['message.edit', $message]]) !!}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM