【发布时间】:2021-09-04 22:41:46
【问题描述】:
我想在自己的视图中编辑一篇博客文章,但是当我将编辑内容进行更改时,我得到一个 419 页面。
这是我的编辑视图,用于编辑由其 id 指定的相关博客:
<div id="body" style="color:#333">
<h1 style="color:#333">Update blog</h1>
<form method="POST" action="{{route('blogSingle',$blog->id)}}">
@method('put')
@csrf
<div class="field">
<label for="title" class="label" style='font-size:1.2rem'>Title</label>
<div class="control">
<input type="text" class="input" name="title" id="title" placeholder="Blog Title" value="{{$blog->title}}">
</div>
</div>
<div class="field">
<label for="body" class="label" style='font-size:1.2rem'>Body</label>
<div class="control">
<textarea type="text" class="textarea" name="body" id="body" placeholder="Blog Description">{{$blog->body}}</textarea>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button type="submit" class="btn btn-secondary">Submit</button>
</div>
</div>
</form>
</div>
我还为每个博客创建了一个视图,在其中,我单击一个按钮以重定向到博客编辑视图,如下所示:
<div id="body">
{{-- Add a variable blog post here --}}
<h1><span>blog single post</span> <span><a href="{{route('blog-edit',$blog->id)}}" class="btn btn-secondary">Edit Blog</a></span></h1>
<div>
<img src="images/grew-a-mustache.jpg" alt="Mustache">
<div class="article">
<h2 class="lead">{{$blog->title}}</h2>
<p class="lead">
{{$blog->body}}
</p>
</div>
</div>
</div>
我所涉及的路线如下:
Route::get('blog-single/{blog}',[BlogController::class,'show'])->name('blogSingle');
Route::get('blog-single/{blog}/edit', [BlogController::class, 'edit'])->name('blog-edit');
Route::put('blog-single/{blog}',[BlogController::class, 'update']);
【问题讨论】:
-
你在那个页面上等了很久吗? 419 表示授权已过期。
-
我几乎立即进行了编辑,只是为了测试它是否有效。但是,我昨天从专门用于创建新博客的 create-blog 视图添加了这些文章,并且它首先插入了 @csrf。我不确定它是否重要。
-
您可以尝试用
@method('PUT')替换@method('put')吗? -
我刚刚做了,但我仍然得到同样的东西。我昨天已将 SESSION_DOMAIN 添加到我的 env 文件中,域为 127.0.01:8000。我添加它是因为当我尝试创建一个新博客时,我的 419 页面也已过期,那是我第一次在我的创建博客视图中添加 @csrf。