3

I am not able to add field which is not available in my database

I have tried adding

$this->crud->addFields([
    [
        'name'        => 'coupon_type',
        'label' => 'Coupon For',
        'type'        => 'select_from_array',
        'options'     => [ 
            // Options
        ],
        'allows_null' => true,
        'default' => 1,
        'attributes' => [
            'id' => 'coupon_type'
        ]
    ]
]);

I want to add fields in my create page.

Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52
Jainam Shah
  • 204
  • 1
  • 9

1 Answers1

2

You can do this by defining accessors for your "virtual" attributes

public function getIsAdminAttribute()
{
    return $this->attributes['admin'] == 'yes';
}

and defining the appends on your model

protected $appends = ['is_admin'];

Find everything in the docs here:

https://laravel.com/docs/5.8/eloquent-serialization#appending-values-to-json

Frnak
  • 6,601
  • 5
  • 34
  • 67