![](/img/trans.png)
[英]After submitting a form i get an error “Sorry, the page you are looking for could not be found.”
[英]When I post a reply with a form i get “Sorry, the page you are looking for could not be found.”
我有一個帖子和一個回復表格。 當我提交表單時,網址是“ http://forum.dev/threads/POST?_token=FIjEkUuNOyFfx8abaiIMEbep2VO1SXYk2b6hqzfT&body=something “
我的看法是:
@if (auth()->check())
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="POST" action="{{ $thread->path() . '/replies' }}">
{{ csrf_field() }}
<div class="form-group">
<textarea name="body" id="body" class="form-control" placeholder="Have something to say?" rows="5"></textarea>
</div>
<button type="submit" class="btn btn-default">Post</button>
</form>
</div>
</div>
@endif
我的控制器是:
public function store(Thread $thread)
{
$thread->addReply([
'body' => request('body'),
'user_id' => auth()->id()
]);
return back();
}
我的線程模型是:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
protected $guarded = [];
public function path()
{
return '/threads/' . $this->id;
}
public function replies()
{
return $this->hasMany(Reply::class);
}
public function creator()
{
return $this->belongsTo(User::class, 'user_id');
}
public function addReply($reply)
{
$this->replies()->create($reply);
}
}
如果我忘記了什么,請告訴我! 任何幫助將不勝感激! 非常感謝你!
我認為您提出了GET請求。 您需要發出POST請求。 因此,請檢查html語法。 還要檢查是否有其他表格可以覆蓋此表格。 我對我的答案很確定,但是使用post方法,您將無法在URL中查看已發送的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.