函数 App\Http\Controllers\EventController::edit() 的参数太少,传递了 0 个,预期正好是 1 个

Too few arguments to function App\Http\Controllers\EventController::edit(), 0 passed and exactly 1 expected

大家好,请帮助我,我是 laravel 的新手,我不知道为什么会出现此错误

Symfony\Component\Debug\Exception\FatalThrowableError 函数 App\Http\Controllers\EventController::edit() 的参数太少,传递了 0 个,预期正好是 1 个

这是我的事件控制器

 ' public function show()
{
    $events = Event::all();
    return view('superadminpage.admin_event.admin_update_event')->with('events', $events);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    $events = Event::find($id);
    return view('superadminpage.admin_event.admin_editform', compact('events', 'id'));
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    $this->validate($request,[
        'title' => 'required',
        'color' => 'required',
        'start_date' => 'required',
        'end_date' => 'required',
    ]);

    $events = Event::find($id);

    $events->title = $request->input('title');
    $events->color = $request->input('color');
    $events->start_date = $request->input('start_date');
    $events->end_date = $request->input('end_date');

    $events->save();

    return redirect('admin_calendar')->with('success', ' has been added');
}

'

这是我的路线

"Route::get('/admin_update_event', 'EventController@show');
 "Route::get('/admin_editform', 'EventController@edit');

这是我的admin_update_event.blade.php

 @foreach ($events as $event)
    <tbody>
        <tr>
            <td>{{ $event->id}}</td>
            <td>{{ $event->title}}</td>
            <td>{{ $event->color}}</td>
            <td>{{ $event->start_date}}</td>
            <td>{{ $event->end_date}}</td>

            <th> <a href="{{ route('edit',['id' => $events->id, 'event' => 1]) }}">
                    Edit </a>
            </th>

        </tr>
    </tbody>
    @endforeach

这是我的admin_editform.blade.php

            <form method="POST" action="{{action('EventController@update')}}">

                {{csrf_field() }}
                <div class="container">
                    <div class="jumnbotron"> 
                        <h1> Update Event </h1>
                    <br>
                <input type="hidden" name="_method" value="UPDATE" />

                <div class="form-group">
            <label for="">Enter name of the Event</label>
            <input type="text" class="form-control" name="title" placeholder="Enter The name" value="{{ $events->title}}">
                </div>

                <div class="form-group">
            <label for="">Choose a Color</label>
            <input type="color" class="form-control" name="color" placeholder="Choose a color" value="{{ $events->color}}">
                </div>

                <div class="form-group">
            <label for="">Enter startdate of the Event</label>
            <input type="datetime-local" class="form-control" name="start_date" class="date" placeholder="Enter The start date" value="{{ $events->start_date}}">
                </div>

                <div class="form-group">
            <label for="">Enter enddate of the Event</label>
            <input type="datetime-local" class="form-control" name="end_date" class="date" placeholder="Enter The end date" value="{{ $events->end_date}}">
                </div>
            {{ method_field('PUT') }}
            <input type="submit" name="submit" class="btn btn-primary" value="add Event data"/>

                    </div>
                </div>
            </form>

问题是您的 "edit" 路由没有参数,而 edit() 方法需要一个 $id 参数。试试这个:

Route::get('/admin_editform/{id}', 'EventController@edit');

请试试这个

   Route::get('/admin_editform/{id}', 'EventController@edit');