Forum

Posting Data to multiple tables with a single form

I have question about, posting data to multiple tables with a single form. Actually I'm beginner with laravel and sximo also.

How to make relations with tables in form view?

Thanks in advance...

neehad
neehad
  • 1 year ago
Creed
Solution

Hello actually is not so hard but yeah you have to learn some base first and i suggest you to get Laravel base at Laracast => http://laracasts.com/

then for run query on multiple table from one form it's like below :

when you create a form => form.blade.php as example (it's html code) but it has to be in relation with a php code as a controller right ?

so in controller you will define your data like below (as i did for mail system)

$data = array(
                'first_name'   => $request->input ('first_name'),
                'last_name'    => $request->input ('last_name'),
                'email_sender' => $request->input ('email_sender'),
                'phone'        => $request->input ('phone'),
                'street'       => $request->input ('street'),
                'city'         => $request->input ('city'),
                'zip'          => $request->input ('zip'),
                'state'        => $request->input ('state'),
                'country'      => $request->input ('country'),
                'subject'      =>$request->input ('request'),
                'note'         => $request->input ('message'),
                'status'       => 'inqueue',
                'created_at'   => $this->getTime (),
                'updated_at'   => $this->getTime ()
            );

then your data is ready for be stored you can simply call that query

DB::table ('tb_contacts')->insert ($data);
DB::table ('tb_contacts1')->insert ($data);
DB::table ('tb_anythingyouwant')->insert ($data);

Got it ?

Thank you Creed for a quick answer... I think I got it :D :D

You are welcome