1
我正面臨使用$ this-> validate($ request,[])顯示錯誤消息的問題;無法在Laravel 5上顯示錯誤消息
路線POST和GET
Route::post('{phone}/{name}/store_location','[email protected]_location');
Route::get('{phone}/{name}','[email protected]');
Store_location控制器
public function store_location($phone, $name ,Restaurant_LocationRequest $request)
{
$this->validate($request, [
'street' => 'required',
'city' => 'required',
'zip' => 'required',
'country' => 'required',
'state' => 'required'
]);
$restaurant_location = Restaurant::locatedAt($phone, $name)->first();
$restaurant_location->restaurant_location()->create($request->all());
return redirect($restaurant_location->phone . '/' . $restaurant_location->name);
}
表顯示錯誤
<form role="form" method="POST" action="/{{ $restaurant->phone }}/{{ $restaurant->name }}/store_location">
@include('restaurant.create_restaurant_location_form')
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</form>
在這下面是我的請求文件 Restaurant_LocationRequest Reques
public function authorize()
{
return true;
}
public function rules()
{
return [
'street' => 'required',
'city' => 'required',
'zip' => 'required',
'country' => 'required',
'state' => 'required'
];
}
它顯示錯誤調用一個成員函數失敗()上的空 –
你可以請提供Restaurant_LocationRequest一些見解? –
我有更新我的問題 –