私は必要に応じて 'name'属性を検証するフォーム要求を持っています。フォームを送信すると、保存せずに作成ページにリダイレクトされますが、エラーメッセージは表示されません。Laravelフォームリクエストの検証
$エラーでvar_dumpを実行すると、それは空です。私は
見る...ここで何が起こっているのかを考え出す助けに感謝したい
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
{{var_dump($errors)}}
コントローラー:
<?php
namespace CRM\Http\Controllers\Settings;
use CRM\Http\Requests;
use CRM\Http\Controllers\Controller;
use CRM\Category;
use CRM\Http\Requests\CategoryFormRequest;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Session;
class CategoriesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return void
*/
public function index()
{
$categories = Category::paginate(15);
return view('settings.categories.index', compact('categories'));
}
/**
* Show the form for creating a new resource.
*
* @return void
*/
public function create()
{
return view('settings.categories.create');
}
/**
* Store a newly created resource in storage.
*
* @param CategoryFormRequest $request
*/
public function store(CategoryFormRequest $request)
{
Category::create($request->all());
Session::flash('flash_message', 'Category added!');
return redirect('settings/categories');
}
/**
* Display the specified resource.
*
* @param int $id
*
* @return void
*/
public function show($id)
{
$category = Category::findOrFail($id);
return view('settings.categories.show', compact('category'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return void
*/
public function edit($id)
{
$category = Category::findOrFail($id);
return view('settings.categories.edit', compact('category'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return void
*/
public function update($id, Request $request)
{
$this->validate($request, ['name' => 'required', ]);
$category = Category::findOrFail($id);
$category->update($request->all());
Session::flash('flash_message', 'Category updated!');
return redirect('settings/categories');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return void
*/
public function destroy($id)
{
Category::destroy($id);
Session::flash('flash_message', 'Category deleted!');
return redirect('settings/categories');
}
}
フォーム要求:
<?php
namespace CRM\Http\Requests;
use CRM\Http\Requests\Request;
class CategoryFormRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required'
];
}
public function messages()
{
return [
'name.required' => 'Please enter a name for this category'
];
}
}
ルート:
Route::group(['middleware' => ['web']], function() {
Route::resource('settings/categories', 'Settings\\CategoriesController');
Route::resource('settings/statuses', 'Settings\\StatusesController');
Route::get('/', function() {
return view('welcome');
});
});
私はこれをstore()の最初の行に入れます。 dd($ request); 私はこの取得:あなたはあなたの問題のために、「ウェブ」のミドルウェアを使用する必要がlaravel 5.2で
Request {#40 ▼
#json: null
#convertedFiles: null
#userResolver: Closure {#211 ▶}
#routeResolver: Closure {#210 ▶}
+attributes: ParameterBag {#42 ▶}
+request: ParameterBag {#41 ▶}
+query: ParameterBag {#48 ▶}
+server: ServerBag {#45 ▶}
+files: FileBag {#44 ▶}
+cookies: ParameterBag {#43 ▶}
+headers: HeaderBag {#46 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/settings/categories"
#requestUri: "/settings/categories"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Store {#240 ▶}
#locale: null
#defaultLocale: "en"
}
。店舗の第一ラインとして? – iKode
@iKode dd($ request)の出力を追加しました。私の質問 – showFocus