英文:
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() 函数的参数太少,期望传入 1 个参数,但传入了 0 个。
这是我的 EventController:
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', '已添加');
}
这是我的路由:
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' => $event->id, 'event' => 1]) }}">
编辑 </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> 更新事件 </h1>
<br>
<input type="hidden" name="_method" value="UPDATE" />
<div class="form-group">
<label for="">输入事件的名称</label>
<input type="text" class="form-control" name="title" placeholder="输入名称" value="{{ $events->title}}">
</div>
<div class="form-group">
<label for="">选择颜色</label>
<input type="color" class="form-control" name="color" placeholder="选择颜色" value="{{ $events->color}}">
</div>
<div class="form-group">
<label for="">输入事件的开始日期</label>
<input type="datetime-local" class="form-control" name="start_date" class="date" placeholder="输入开始日期" value="{{ $events->start_date}}">
</div>
<div class="form-group">
<label for="">输入事件的结束日期</label>
<input type="datetime-local" class="form-control" name="end_date" class="date" placeholder="输入结束日期" value="{{ $events->end_date}}">
</div>
{{ method_field('PUT') }}
<input type="submit" name="submit" class="btn btn-primary" value="添加事件数据"/>
</div>
</div>
</form>
英文:
hi guys please help me im new to the laravel i don't know why i have this error
Symfony\Component\Debug\Exception\FatalThrowableError
Too few arguments to function App\Http\Controllers\EventController::edit(), 0 passed and exactly 1 expected
this is my EventController
' 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');
}
'
this is my route
"Route::get('/admin_update_event', 'EventController@show');
"Route::get('/admin_editform', 'EventController@edit');
this is my 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
this is my 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>
答案1
得分: 2
问题出在你的 "edit" 路由没有参数,而 edit()
方法需要一个 $id
参数。尝试这样做:
Route::get('/admin_editform/{id}', 'EventController@edit');
英文:
The issue is your "edit" route having no parameters and the edit()
method expects a $id
parameter. Try this:
Route::get('/admin_editform/{id}', 'EventController@edit');
答案2
得分: 0
请尝试这个:
Route::get('/admin_editform/{id}', 'EventController@edit');
英文:
Please try this
Route::get('/admin_editform/{id}', 'EventController@edit');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论