Welcome Guest, Not a member yet? Register   Sign In
Call function in model before validation
#1

Hi guys,
I have a model with the following validation rule.

PHP Code:
'slug'  => 'is_unique[products.slug,ID,{ID}]|alpha_dash' 

I would like to automatically generate a slug when none is provided, so I added:

PHP Code:
protected $beforeInsert = ['generateSlug'];

protected function 
generateSlug(array $data)
    {
        if (empty(
$data['data']['slug']))
        {
            
$data['data']['slug'] = url_title($data['data']['name'], '-'true);
        }

        return 
$data;
    } 


The problem seems that validation rules are evaluated before `beforeInsert` callback is called.

Could you help me?
Thanks.
Reply


Messages In This Thread
Call function in model before validation - by RobT - 11-19-2019, 10:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB