1

我试图在 Request 中添加一些验证,我得到“BadMethodCallException Method getPath does not exist”错误。我只在邮递员中发送空值来测试它。例如:

{

“名称”:空

}

这是我的控制器:

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');
4

0 回答 0