1

I was trying to add some validation in Request ,I get "BadMethodCallException Method getPath does not exist" error. I am sending just null value in postman to test it. for example:

{

"name":null

}

Here is my controller:

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 Request:

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:

 Route::post('settings/addCommunicationType', 'SettingsController@addCommunicationType');
user3810794
  • 263
  • 2
  • 6
  • 23

0 Answers0