Laravel-admin: Array to string conversion

Created on 27 Aug 2018  ·  2Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: #.#.#
  • PHP Version:
  • Laravel-admin: #.#.#

Description:

Hello.
I'm trying to make multipleSelect, pull out an abbushArray to string conversion
In the table for the field category didvarchar
I want to get data in the table in the form of 1,2
How to implement this?

Steps To Reproduce:

$form->multipleSelect('category')->options([1 => 'one', 2 => 'two']);

Most helpful comment

You should define a accessor and a mutator for column category in your model to handle the string type

    public function getCategoryAttribute($value)
    {
        return explode(',', $value);
    }

    public function setCategoryAttribute($value)
    {
        $this->attributes['category'] = implode(',', $value);
    }

All 2 comments

You should define a accessor and a mutator for column category in your model to handle the string type

    public function getCategoryAttribute($value)
    {
        return explode(',', $value);
    }

    public function setCategoryAttribute($value)
    {
        $this->attributes['category'] = implode(',', $value);
    }

Many thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaalngf picture xiaalngf  ·  3Comments

wangwenfan picture wangwenfan  ·  3Comments

taimaiduc picture taimaiduc  ·  3Comments

cdhraesaemer picture cdhraesaemer  ·  3Comments

joernroeder picture joernroeder  ·  3Comments