亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法通過按鈕發布數據

無法通過按鈕發布數據

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 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號