samedi 21 avril 2018

How to add custom validation rules in CreateContainerRequest

I am trying to add custom validation rules to one of my Example container.

which i generated using the apiato framework. below is my code.

<?php

namespace App\Containers\Example\UI\API\Requests;

use App\Ship\Parents\Requests\Request;

/**
 * Class CreateExampleRequest.
 */
class CreateExampleRequest extends Request
{

    /**
     * The assigned Transporter for this Request
     *
     * @var string
     */
    // protected $transporter = \App\Ship\Transporters\DataTransporter::class;

    /**
     * Define which Roles and/or Permissions has access to this request.
     *
     * @var  array
     */
    protected $access = [
        'permissions' => '',
        'roles'       => '',
    ];

    /**
     * Id's that needs decoding before applying the validation rules.
     *
     * @var  array
     */
    protected $decode = [
        // 'id',
    ];

    /**
     * Defining the URL parameters (e.g, `/user/{id}`) allows applying
     * validation rules on them and allows accessing them like request data.
     *
     * @var  array
     */
    protected $urlParameters = [
        // 'id',
    ];



    /**
     * @return  array
     */

    public function lesser_than()
    {
      $result = array();
      $va=$this->getValidatorInstance();
      $va->sometimes('day_value','nullable|numeric',function($input){
        return $input->month_value>0

      });
   }

    public function rules()
    {
        return [
          'day_value': 'required',
          'month_value':'required',
          // 'id' => 'required',
            // '{user-input}' => 'required|max:255',
          ];
    }

    /**
     * @return  bool
     */
    public function authorize()
    {
        return $this->check([
            'hasAccess',
        ]);
    }
}

as expected the above code does not work, but i just want to perform one validation i.e

day_value>month_value and day_value>0 and month_value>0

How can i do that with using apiato framework. i'm a beginner to laravel and apiato.

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HiyCHW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire