我有一个像这样的简单代码(更多或更少)。
路线:
Route::post('car', 'CarController@store')->name('insert_car.store');
Route::post('car-italian', 'CarItalianController@store')->name('insert_car-italian.store');
控制器:
class CarController extends Controller
{
public function store(StoreCarRequest $request)
{
return Car::create($request->validated()) // Calling 'car-italian' route, the code fails here!
}
}
class CarItalianController extends Controller
{
public function store(StoreCarItalianRequest $request)
{
$input_parameters = $request->validated();
$t = [
'model' => $input_parameters['modello'],
'door' => $input_parameters['porte'],
];
return (new CarController)->store(new StoreCarRequest($t));
}
}
表格要求:
class StoreCarRequest extends FormRequest
{
public function rules()
{
return [
'model' => 'string',
'door' => 'integer'
];
}
}
class StoreCarItalianRequest extends FormRequest
{
public function rules()
{
return [
'modello' => 'string',
'porte' => 'integer'
];
}
}
当我调用路由car-italian
时,它失败并显示消息:
Call to a member function validated() on null
有人能帮我吗?我花了一整天的时间:-/
谢谢