我試圖在我正在構建的站點的後端實現類別創建表單。這個想法是讓它與現有類別的索引在同一頁面上。但是,目前,創作系統什麼都不做。它不會返回錯誤;直接查詢時沒有任何數據顯示在數據庫中;根據重定向,頁面上不會顯示新的內容。由於沒有任何反饋,我正在摸索這條路線的不同/錯誤,而我之前對於後期製作機制所做的非常類似的路線。在任何情況下,這裏的相關創作形式:Laravel:資源控制器'store'方法不會產生任何結果,也不會產生錯誤
<form method="POST" action="{{ route('categories.store') }}" data-parsley-validate>
<div class="form-group">
<label name="name">Category Name:</label>
<input id="name" name="name" class="form-control" required maxlength="255">
</div>
<input type="submit" value="Create" class="btn btn-lg btn-block">
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
下面是從CategoryController的 '商店' 方法:
public function store(Request $request)
{
$this->validate($request, array(
'name' => 'required|max:255'
));
$category = new Category;
$category->name = $request->name;
$category->save();
Session::flash('success', 'Category has been created!');
return redirect()->route('categories.index');
}
這裏是web.php路線文件:
<?php
Route::get('/', '[email protected]');
Route::get('/contact', '[email protected]');
Route::resource('posts', 'PostController');
Route::resource('categories', 'CategoryController');
Route::get('blog/{slug}', '[email protected]')->where('slug', '[\w\d\-\_]+');
Route::get('blog', '[email protected]');
Auth::routes();
Route::get('/home', '[email protected]');
?>
同樣,我沒有收到任何錯誤消息,只是提交按鈕什麼都不做。提前致謝!
要嘗試的其他事情是將所有東西都包裹在一個try catch中。 – Paul
以上以及推薦的鏈接都沒有影響。 RE:try-catch語句的建議,我假設這個想法是在try子句中包含整個當前的商店操作? – user968270