0

Sorry if My English is Bad.

I Have Table Just like this,Only Two Col :

Meta-col , Value-col

Now I Get My Inputs at Array Like This:

$settings=$request->all();

So My Result is something like This :

{
"_method": "PATCH",
"_token": "Yk3l3GsacKV6plkXH0zNKLVL2HcYjZbg2kB8KeAp",
"site_title": test,
"blog_description": blog test,
"admin_email": [email protected],
"site_language": "eng",
...
}

Well,I Want Save Index in Meta-col & Values in Value-col.

My Table Should be Like This :

Meta-col           Value-col
 ----------        ----------
 site_title          value 
 blog_description  blog test
  .......           ....

I try This Codes But Not Working and Get Error :

$settings->save();

or

 foreach ($metas as $meta =>$value){
       echo "<p style='color:red;text-align: center'>". $meta ."</p>";
       echo "<p style='color:blue;text-align: center'>". $value ."</p>";
 }

Well,With This Foreach I can Get Each Meta & Value separate But Still I Don't Know How To Manage it.

And Also Tested Some other Code's But Still Not Work.

1 Answer 1

4

If you have a Model for your table in database you can do :

Say your Model is MyModel

foreach ($metas as $meta =>$value){
        $m = new MyModel();
        $m->Meta_col = $meta;
        $m->Value_col = $value;
        $m->save();
 }

In order for your variable to be save()d to the database it has to be of type

class MyModel extends Model {} where Model being Illuminate\Database\Eloquent\Model.

I didn't catch your laravel version so here is a starter from the last version.

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

2 Comments

yes.It Work's. Thanks Buddy. My laravel version is 5.6
Np. Glad to help

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.