I try to create some API and add custom validation:
controller :
use App\Http\Requests\Penggunarequest;
class LogRegAPI extends Controller {
public function register(Penggunarequest $penggunarequest) {
$input = $penggunarequest->all();
$nama = $input['name'];
$alamat = $input['address'];
//other logical thing
validation request :
namespace App\Http\Requests;
use App\Http\Requests\Request;
class Penggunarequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|String',
'address' => 'required|String',
];
}
}
If i send post data via controller by using browser, it will redirect to form post if have error response, but I want to post it via android, evertything work well except if it have error response it display 302. How to make error response show in custom JSON?