KalimeroMK
3 days ago

Validate parent_id in request class

Posted 3 days ago by KalimeroMK

Have edit category method and want to validate the parent_id is not the same as the category id to prevent category become a parent of itself. Try this code but no joy

class Update extends FormRequest
{
    use CanAuthorise;

    /**
     * @var mixed
     */
    private $id;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|string|255',
            'parent_id' => 'different:' . $this->id,
    //or 'parent_id' => 'different:id' 
        ];
    }
}

Please sign in or create an account to participate in this conversation.