Welcome Guest, Not a member yet? Register   Sign In
How to validate an API REST?
#1

(This post was last modified: 04-17-2020, 10:37 AM by MatheusCastro.)

Hello, 

I'm extending Resource Controller

In situations that are passed as GET I can validate this way:

PHP Code:
public function index()
    {
        // this
        if (!$this->validate([
            'page'    => 'required|is_natural_no_zero|max_length[11]',
            'city_id' => 'required|is_natural_no_zero|max_length[11]',
            'search'  => 'permit_empty|max_length[50]'

        ])) return $this->fail($this->validator->getErrors());

      // continue
    

However, when it is necessary to pass the parameter through the function, how to solve this?


PHP Code:
    public function show($id null)
    {
        
// error
        if (!$this->validate([
            $id => 'required|is_natural_no_zero|max_length[11]',
            
        
])) return $this->fail($this->validator->getErrors());

       // continue
    



Can anyone help?
Reply


Messages In This Thread
How to validate an API REST? - by MatheusCastro - 04-17-2020, 10:36 AM
RE: How to validate an API REST? - by jreklund - 04-17-2020, 12:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB