为了账号安全,请及时绑定邮箱和手机立即绑定

无法通过按钮发布数据

无法通过按钮发布数据

PHP
ibeautiful 2023-03-26 14:07:36
我正在尝试通过按下按钮通过隐藏字段将数据发布到数据库但是我面临的错误是419 Page Expired这是我的观点:-<div><h1> All Posts </h1>@if(count($user) > 0)  @foreach($user as $post)<form action="/f" method="POST"><input type="hidden" id="friends" name="friends" value="{{$post->id}}" /><button type="submit" class="btn btn-primary">                                    {{ __('chat') }}                                </button></form><div class="well"> <a href="/profile/1"<button class="button btn-success">chat</button>></a>  <h3>{{$post->title}}</h3>  <h4>{{$post->body}}</h4>  <small>written on {{$post->created_at}}</small></div>@endforeach@else   <p>No Forms Found</p>@endif</div>这是我的路线:-Route::post('/f', 'FriendsController@store');这是我的控制器:-<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;class FriendsController extends Controller{    public function store(Request $request){   dd($request->all());    post::create([        'friends' => $request->friends,        ]);     return redirect('/profile/' . auth()->user()->id);}}我可能在我的商店方法中犯了错误请检查并让我知道它有什么问题我只是一个初学者 - 谢谢
查看完整描述

1 回答

?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

错误 419 表示页面已过期,在 laravel 中,它来自在发出非 GET 请求时没有或无效的 CSRF 令牌。您需要在表单中添加一个 CRSF 令牌,例如在表单声明之后添加 @csrf:


<form action="/f" method="POST">

@csrf

<input type="hidden" id="friends" name="friends" value="{{$post->id}}" />

或者这样:


<form action="/f" method="POST">

 {{csrf_field()}}

<input type="hidden" id="friends" name="friends" value="{{$post->id}}" />


查看完整回答
反对 回复 2023-03-26
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信