0

Here is My Json Request

When insert this code into my database the slide column will inserted as Null

How Can Insert My slide value into my database.. slide column is Json type

7
  • Did you cast that in you model? like $casts = ['slide' => 'json'] ? Commented Mar 9, 2021 at 9:40
  • @MiqayelSrapionyan yes public function setSlidesAttribute($value) { $this->attributes['slides'] = json_encode($value); } public function getSlidesAttribute($value) { return json_decode($value); } this is the code Commented Mar 9, 2021 at 9:41
  • I think you don't need it to do manual, please use my example, and tell me the result Commented Mar 9, 2021 at 9:44
  • @MiqayelSrapionyan I Have tried protected $casts = [ 'slides' => 'json', ]; BUT still The Inserting value is NULL Commented Mar 9, 2021 at 9:48
  • your input name is slide but you used slides, have you checked the database column name also to be slide? Commented Mar 9, 2021 at 9:50

1 Answer 1

1

You can use Laravel attributes casting in model like this.

protected $casts = [
    'slide' => 'json'
];

Docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.