Api: [L5.1] API FormRequest working example?

Created on 5 Aug 2015  Â·  6Comments  Â·  Source: dingo/api

@jasonlewis Hi Jason, I tried to implement the FormRequest for creating a post, but not able to do so successfully. I basically used it like the Laravel form request, but instead used the API version you just added the same way. I checked out the documentation but didn't see a concrete example on how to do this. Do you mind putting together a working example to show how the API FormRequest is working for validation?

Most helpful comment

Hallo,

just change the extend of your Request to the Dingo FormRequest and use it like you used it before.

Best regards,
Jochen

namespace App\Http\Requests;

use Dingo\Api\Http\FormRequest;

class TestRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            // your rules
        ];
    }
}

All 6 comments

I wanna se too
Em 05/08/2015 1:06 PM, "MovingGifts" [email protected] escreveu:

@jasonlewis https://github.com/jasonlewis Hi Jason, I tried to
implement the FormRequest for creating a post, but not able to do so
successfully. I basically used it like the Laravel form request, but
instead used the API version you just added the same way. I checked out the
documentation but didn't see a concrete example on how to do this. Do you
mind putting together a "sample" code to show how the API FormRequest is
working for validation?

—
Reply to this email directly or view it on GitHub
https://github.com/dingo/api/issues/562.

Hallo,

just change the extend of your Request to the Dingo FormRequest and use it like you used it before.

Best regards,
Jochen

namespace App\Http\Requests;

use Dingo\Api\Http\FormRequest;

class TestRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            // your rules
        ];
    }
}

Just like @jochenmanz has shown above. I'll document it a bit more though.

Let me know if you have any problems.

Actually the documentation has not yet reflected this. is it going to be updated?

Thank you

Right now this method is not working: Class 'Illuminate\Foundation\HttpFormRequest' not found

In the FormRequest.php we want to extend the original FormRequest but lumen doesn't have this class.

use Illuminate\Foundation\Http\FormRequest as IlluminateFormRequest;

class FormRequest extends IlluminateFormRequest
Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaoshanliang picture yaoshanliang  Â·  4Comments

pedrolari picture pedrolari  Â·  3Comments

jdforsythe picture jdforsythe  Â·  3Comments

jhayiwg picture jhayiwg  Â·  3Comments

pongz79 picture pongz79  Â·  4Comments