[英]POST request is not tallied with the form in Laravel Blade
I am a newbie in Laravel.我是 Laravel 的新手。
My problem is, when I tried to update my form, it kept saying that the tablename not found eventhough I already mentioned it inside my Model.我的问题是,当我尝试更新我的表单时,它一直说找不到表名,尽管我已经在 Model 中提到了它。 But when I debugged, I found that the request is not the same from what I put inside my form.
但是当我调试时,我发现请求与我在表单中输入的不一样。
But my form actually doesn't have that.但我的表格实际上没有。
Any idea how this is happening, guys?知道这是怎么回事吗,伙计们? Pretty sure I missed something but unsure what is it.
很确定我错过了一些东西,但不确定是什么。
Event Model事件 Model
class Event extends Model
{
//
protected $fillable = ['title', 'objective', 'date', 'venue', 'description', 'slug'];
public function getRouteKeyName()
{
return 'slug';
}
}
Event Controller事件 Controller
class EventController extends Controller
{
public function update(Request $request, Event $event)
{
//
$validated = $request->validate([
'title' => 'required|string|unique:event|min:5|max:100',
'objective' => 'required|string|min:5|max:2000',
'date' => 'required|string|min:5|max:2000',
'venue' => 'required|string|min:5|max:2000',
'description' => 'required|string|min:5|max:2000'
]);
// Create slug from title
$validated['slug'] = Str::slug($validated['title'], '-');
// Update Post with validated data
$event->update($validated);
// Redirect the user to the created post woth an updated notification
return redirect(route('events.edit', [$event->slug]))->with('notification', 'Event updated!');
}
Edit Blade Page编辑刀片页面
<form method="post" action="{{ route('events.update', [$event->slug]) }}">
@csrf
@method('patch')
@include('partials.errors')
<div class="field">
<label class="label">Title</label>
<div class="control">
<input type="text" name="title" value="{{ $event->title }}" class="input" placeholder="Title" minlength="5" maxlength="100" required />
</div>
</div>
<div class="field">
<label class="label">Objective</label>
<div class="control">
<textarea name="content" class="textarea" placeholder="Content" minlength="5" maxlength="2000" required rows="10">{{ $event->objective }}</textarea>
</div>
</div>
<div class="field">
<label class="label">Date</label>
<div class="control">
<input type="text" name="title" value="{{ $event->date }}" class="input" placeholder="Title" minlength="5" maxlength="100" required />
</div>
</div>
<div class="field">
<label class="label">Venue</label>
<div class="control">
<input type="text" name="title" value="{{ $event->venue }}" class="input" placeholder="Title" minlength="5" maxlength="100" required />
</div>
</div>
<div class="field">
<label class="label">Description</label>
<div class="control">
<textarea name="content" class="textarea" placeholder="Content" minlength="5" maxlength="2000" required rows="10">{{ $event->description }}</textarea>
</div>
</div>
<div class="field">
<div class="control">
<button type="submit" class="button is-link is-outlined">Update</button>
</div>
</div>
</form>
Thank you for your time!感谢您的时间!
You need to change the name
attribute of Date, Venue and Description and Objective.您需要更改 Date、Venue 和 Description 和 Objective 的
name
属性。
On your edit blade page, the input names are alternating 'title' and 'content'在您的编辑刀片页面上,输入名称是交替的“标题”和“内容”
can you rename the input names so that they can be unique您可以重命名输入名称,以便它们可以是唯一的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.