Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to set default values of fields to empty instead of null


I am using Laravel 5.4 and building API for Android and Iphone. I have Set Default value to null in phpmyadmin but my mobile developers do not want null values in response. There are many APIs so I am looking for short and perfect method.

  1. I tried to find something in Laravel model that can help me. I tried following code as well.
  2. Also tried setting default value in phpmyadmin but it does not accepts default: "As defined" is equal to empty value.
  3. Third option could be to loop through laravel Model response and convert null to Empty or zero based on data type but that will increase processing time and will increase our most of work as well.

    public static function boot() { parent::boot();
    self::creating(function ($my_model) {
    $my_model->some_prop = $my_model->some_prop >= 42 ? $my_model->some_prop: defaultValue();

Is there something in Laravel in Model section or somewhere else where I can set Default value to empty fields when field does contain any value or is there any other solution or suggestion means how I can handle this problem?

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to set default values of fields to empty instead of null


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription