Я пытался добавить некоторую проверку в запрос, я получаю сообщение об ошибке «Метод BadMethodCallException getPath не существует». Я отправляю только нулевое значение в почтальоне, чтобы проверить его. Например:
{
"имя": ноль
}
Вот мой контроллер:
namespace Modules\Settings\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Http\JsonResponse;
use Modules\Settings\Repositories\SettingsInterface;
use Modules\Settings\Http\Requests\AddCommunicationType;
class SettingsController extends Controller
{
public function addCommunicationType(AddCommunicationType $request)
{
$data = json_decode(json_encode($request->all()));
$com=$this->settingRepo->addCommunicationType($data);
return response()->json($com);
}
}
Запрос AddCommunicationType:
namespace Modules\Settings\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AddCommunicationType extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'name'=>'required',
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
public function messages() {
return [
'name.required' => 'Name is required.',
];
}
}
Маршрут:
Route::post('settings/addCommunicationType', 'SettingsController@addCommunicationType');