我用laravel自定義表單要求與命令php artisan make:request AddressBookRequest
和使用,要求在我的控制器,如:
路線在自定義表單請求沒有找到
public function add_address_book($lang,$user_id,AddressBookRequest $request){
dd($request);
}
當我運行API路線laravel顯示:
NotFoundHttpException in RouteCollection.php line 161:
但是,當我改變AddressBookRequest
到Request
喜歡:
public function add_address_book($lang,$user_id,Request $request){
dd($request);
}
阿比工作正常
AddressBookRequest:
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class AddressBookRequest 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 [
'title' => 'required',
'address' => 'required',
'latitude' => 'required',
'longitude' => 'required'
];
}
public function messages()
{
return [
'title.required' => trans('address_book.title_required'),
'address.required' => trans('address_book.address_required'),
'latitude.required' => trans('address_book.latitude_required'),
'longitude.required' => trans('address_book.longitude_required'),
];
}
}
AddressBookController usecases:
<?php namespace App\Http\Aggregate\Address_book\Controller\v1_0;
use App\Http\Requests\AddressBookRequest;
use Illuminate\Routing\Controller as BaseController;
use EventHomes\Api\ApiController;
use JWTAuth;
class AddressBookController extends BaseController
{
和路由:
Route::group(['namespace' => 'Aggregate\Address_book\Controller\v1_0', 'middleware' => 'jwt.auth', 'prefix' => 'api/v1.0/{lang}'], function() {
Route::post('customer/{id}/address_book', '[email protected]_address_book');
});
我如何解決它以使用自定義請求?
任何幫助將不勝感激
一下添加到控制文件的頂部**使用App \ HTTP \請求\ AddressBookRequest; ** – Anish
我補充,但它仍然無法正常工作 – amirali
你現在做了什麼錯誤? – Anish