Elastic best practices for key / value type table

My application is a CMS designed for business websites. I have a business_info table that looks like this:

id  | field         | value
-----------------------------------------
1   | name          | Testing Company
2   | official name | Testing Company LLC
3   | main_location | The Bay Area
4   | year          | 1999
5   | address       | 55 Street Rd
6   | suite         | Unit 5
7   | city          | Anytown
8   | state         | CA
9   | zip           | 55555
10  | tollfree      | 1(888) 555-5555

I don’t think that the current Eloquent model will work to effectively manage this information, so I expanded it and started working on a more useful model. I would like to be able to do something like:

$business_info->zip = "66666";
$business_info->save();

This is what I have so far, but I'm not sure how to do it:

class Business_Info extends Eloquent
{
    public static $table = 'business_info';

    public static function all()
    {
        $business_info_rows = with(new static)->query()->get();
        foreach ($business_info_rows as $business_info_row)
        {
            $business_info[$business_info_row->attributes['field']] = $business_info_row->attributes['value'];
        }
        return $business_info;
    }

    public function __set($key, $value)
    {

    }
}

Perhaps someone can offer some advice on how to proceed, or perhaps a different approach? Thank!

+5
source share
1 answer

, __set. , , .

public function __set($key, $value)
{
    $this->set_attribute('field', $key);
    $this->set_attribute('value', $value);
}

field value , - $business_info->zip = "12345";

-, ? , . , , .

+2

All Articles