How to Save an Array data in JSON using LARAVEL ControllerHow to Use Order By for Multiple Columns in Laravel 4?Laravel 4: how to “order by” using Eloquent ORMHow to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel 'Data Missing' on saveLaravel save / update many to many relationshiploop through an array of request data and save per set to the database laravelSaving data from a nested JSON decoded array into a Laravel DBretrieve data with where condition laravel 5.2 into controllerArray gets converted to JSON in MySQL database (Laravel)Laravel array how to save to database
Is surviving this (blood loss) scenario possible?
In this iconic lunar orbit rendezvous photo of John Houbolt, why do arrows #5 and #6 point the "wrong" way?
May I use a railway velocipede on used British railways?
Why teach C using scanf without talking about command line arguments?
The most secure way to handle someone forgetting to verify their account?
Why is Google approaching my VPS machine?
Term “console” in game consoles
Demographic consequences of closed loop reincarnation
How to find location on Cambridge-Mildenhall railway that still has tracks/rails?
Random piece of plastic
Locked-up DOS computer beeped on keypress. What mechanism caused that?
Desecrating Shabbos to ask a Gadol to daven for a patient?
Is straight-up writing someone's opinions telling?
Did Hitler say this quote about homeschooling?
Is encryption still applied if you ignore the SSL certificate warning for self signed?
How can electric field be defined as force per charge, if the charge makes its own, singular electric field?
What causes a rotating object to rotate forever without external force—inertia, or something else?
Should I use a resistor between the gate driver and MOSFET (gate pin)?
How fast does a character need to move to be effectively invisible?
Difference between c++14 and c++17 using: `*p++ = *p`
Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?
"This used to be my phone number"
Strategy to pay off revolving debt while building reserve savings fund?
Why does a tetrahedral molecule like methane have a dipole moment of zero?
How to Save an Array data in JSON using LARAVEL Controller
How to Use Order By for Multiple Columns in Laravel 4?Laravel 4: how to “order by” using Eloquent ORMHow to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel 'Data Missing' on saveLaravel save / update many to many relationshiploop through an array of request data and save per set to the database laravelSaving data from a nested JSON decoded array into a Laravel DBretrieve data with where condition laravel 5.2 into controllerArray gets converted to JSON in MySQL database (Laravel)Laravel array how to save to database
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to save this data generated by a create.blade.php view,
after I press submit button, the console log output is like the code below
"kode_trx": "PO-2019030004",
"no_po": "0005/DIN/III/2019",
"pic_po": "Carlo Donadini",
"pic_telp": "+39438778020",
"top": "RRRRR",
"supplier_id": "1",
"delivery_date": "28-03-2019",
"created_by_id": "1",
"total_barang": "7",
"grand_total": "122500000",
"tb_detail_po": [
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"4",
"17500000",
"70000000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
],
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"3",
"17500000",
"52500000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
]
]
so I want to save it into 2 differen table, table purchases and purchase_details
how I suppose to write my code in POController in method store? ???
database laravel eloquent
add a comment |
I want to save this data generated by a create.blade.php view,
after I press submit button, the console log output is like the code below
"kode_trx": "PO-2019030004",
"no_po": "0005/DIN/III/2019",
"pic_po": "Carlo Donadini",
"pic_telp": "+39438778020",
"top": "RRRRR",
"supplier_id": "1",
"delivery_date": "28-03-2019",
"created_by_id": "1",
"total_barang": "7",
"grand_total": "122500000",
"tb_detail_po": [
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"4",
"17500000",
"70000000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
],
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"3",
"17500000",
"52500000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
]
]
so I want to save it into 2 differen table, table purchases and purchase_details
how I suppose to write my code in POController in method store? ???
database laravel eloquent
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08
add a comment |
I want to save this data generated by a create.blade.php view,
after I press submit button, the console log output is like the code below
"kode_trx": "PO-2019030004",
"no_po": "0005/DIN/III/2019",
"pic_po": "Carlo Donadini",
"pic_telp": "+39438778020",
"top": "RRRRR",
"supplier_id": "1",
"delivery_date": "28-03-2019",
"created_by_id": "1",
"total_barang": "7",
"grand_total": "122500000",
"tb_detail_po": [
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"4",
"17500000",
"70000000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
],
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"3",
"17500000",
"52500000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
]
]
so I want to save it into 2 differen table, table purchases and purchase_details
how I suppose to write my code in POController in method store? ???
database laravel eloquent
I want to save this data generated by a create.blade.php view,
after I press submit button, the console log output is like the code below
"kode_trx": "PO-2019030004",
"no_po": "0005/DIN/III/2019",
"pic_po": "Carlo Donadini",
"pic_telp": "+39438778020",
"top": "RRRRR",
"supplier_id": "1",
"delivery_date": "28-03-2019",
"created_by_id": "1",
"total_barang": "7",
"grand_total": "122500000",
"tb_detail_po": [
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"4",
"17500000",
"70000000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
],
[
"BRG-2019030004",
"Electric Deep Fryer",
"SC-81",
"290",
"440",
"310",
"3",
"17500000",
"52500000",
" ",
"4",
"PO-2019030004",
"0005/DIN/III/2019",
"1",
"5"
]
]
so I want to save it into 2 differen table, table purchases and purchase_details
how I suppose to write my code in POController in method store? ???
database laravel eloquent
database laravel eloquent
asked Mar 26 at 9:54
I Gede Adi PutraI Gede Adi Putra
407 bronze badges
407 bronze badges
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08
add a comment |
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08
add a comment |
3 Answers
3
active
oldest
votes
You can store the data on table purchase
like below
class POController extends Controller
public function store(Request $request)
$purchase = Purchase::create([
"id_penerimaan" => $request->no_nota,
"id_customer" => $request->customer,
"id_karyawan" => $request->karyawan,
"tgl_penerimaan" => CarbonCarbon::now()->format('Y-m-d H:i:s'),
]);
return $purchase;
And for the table purchase_details
if you use Observer it would be great
Example of Observer :
class UserObserver
public function created(Purchase $purchase)
if (request()->tb_detail_po)
foreach(request()->tb_detail_po as $detail)
PurchaseDetail::create([
'id_purchase' => $purchase->id,
'id_penerimaan' => request()->no_nota,
'id_karyawan' => $detail[9],
'id_kategori' => $detail[8],
'sn_barang' => $detail[1],
'nama_barang' => $detail[0],
'kelengkapan' => $detail[2],
'keluhan' => $detail[3],
'id_garansi' => $detail[10],
'id_status' => '1',
'kondisi' => '1'
]);
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
add a comment |
$result = $request->all();
$created = Your Model::create([Your Data For Table 1]);
if($created)
foreach($request->tb_detail_po as $details)
Your Model2::create([Your Detail Data For Table 2]);
add a comment |
Try to use **JSON_DECODE($data)** OR **JSON_ENCODE($data)**
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354187%2fhow-to-save-an-array-data-in-json-using-laravel-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can store the data on table purchase
like below
class POController extends Controller
public function store(Request $request)
$purchase = Purchase::create([
"id_penerimaan" => $request->no_nota,
"id_customer" => $request->customer,
"id_karyawan" => $request->karyawan,
"tgl_penerimaan" => CarbonCarbon::now()->format('Y-m-d H:i:s'),
]);
return $purchase;
And for the table purchase_details
if you use Observer it would be great
Example of Observer :
class UserObserver
public function created(Purchase $purchase)
if (request()->tb_detail_po)
foreach(request()->tb_detail_po as $detail)
PurchaseDetail::create([
'id_purchase' => $purchase->id,
'id_penerimaan' => request()->no_nota,
'id_karyawan' => $detail[9],
'id_kategori' => $detail[8],
'sn_barang' => $detail[1],
'nama_barang' => $detail[0],
'kelengkapan' => $detail[2],
'keluhan' => $detail[3],
'id_garansi' => $detail[10],
'id_status' => '1',
'kondisi' => '1'
]);
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
add a comment |
You can store the data on table purchase
like below
class POController extends Controller
public function store(Request $request)
$purchase = Purchase::create([
"id_penerimaan" => $request->no_nota,
"id_customer" => $request->customer,
"id_karyawan" => $request->karyawan,
"tgl_penerimaan" => CarbonCarbon::now()->format('Y-m-d H:i:s'),
]);
return $purchase;
And for the table purchase_details
if you use Observer it would be great
Example of Observer :
class UserObserver
public function created(Purchase $purchase)
if (request()->tb_detail_po)
foreach(request()->tb_detail_po as $detail)
PurchaseDetail::create([
'id_purchase' => $purchase->id,
'id_penerimaan' => request()->no_nota,
'id_karyawan' => $detail[9],
'id_kategori' => $detail[8],
'sn_barang' => $detail[1],
'nama_barang' => $detail[0],
'kelengkapan' => $detail[2],
'keluhan' => $detail[3],
'id_garansi' => $detail[10],
'id_status' => '1',
'kondisi' => '1'
]);
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
add a comment |
You can store the data on table purchase
like below
class POController extends Controller
public function store(Request $request)
$purchase = Purchase::create([
"id_penerimaan" => $request->no_nota,
"id_customer" => $request->customer,
"id_karyawan" => $request->karyawan,
"tgl_penerimaan" => CarbonCarbon::now()->format('Y-m-d H:i:s'),
]);
return $purchase;
And for the table purchase_details
if you use Observer it would be great
Example of Observer :
class UserObserver
public function created(Purchase $purchase)
if (request()->tb_detail_po)
foreach(request()->tb_detail_po as $detail)
PurchaseDetail::create([
'id_purchase' => $purchase->id,
'id_penerimaan' => request()->no_nota,
'id_karyawan' => $detail[9],
'id_kategori' => $detail[8],
'sn_barang' => $detail[1],
'nama_barang' => $detail[0],
'kelengkapan' => $detail[2],
'keluhan' => $detail[3],
'id_garansi' => $detail[10],
'id_status' => '1',
'kondisi' => '1'
]);
You can store the data on table purchase
like below
class POController extends Controller
public function store(Request $request)
$purchase = Purchase::create([
"id_penerimaan" => $request->no_nota,
"id_customer" => $request->customer,
"id_karyawan" => $request->karyawan,
"tgl_penerimaan" => CarbonCarbon::now()->format('Y-m-d H:i:s'),
]);
return $purchase;
And for the table purchase_details
if you use Observer it would be great
Example of Observer :
class UserObserver
public function created(Purchase $purchase)
if (request()->tb_detail_po)
foreach(request()->tb_detail_po as $detail)
PurchaseDetail::create([
'id_purchase' => $purchase->id,
'id_penerimaan' => request()->no_nota,
'id_karyawan' => $detail[9],
'id_kategori' => $detail[8],
'sn_barang' => $detail[1],
'nama_barang' => $detail[0],
'kelengkapan' => $detail[2],
'keluhan' => $detail[3],
'id_garansi' => $detail[10],
'id_status' => '1',
'kondisi' => '1'
]);
edited Mar 27 at 7:24
answered Mar 26 at 10:40
SethuSethu
6704 silver badges8 bronze badges
6704 silver badges8 bronze badges
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
add a comment |
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
can you help me with the CI syntax to laravel syntax ?
– I Gede Adi Putra
Mar 27 at 5:16
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
I've modified the code with data as you've asked, you can try it
– Sethu
Mar 27 at 7:28
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
thanks, I will try
– I Gede Adi Putra
Mar 28 at 9:00
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
hi can you help me with update ?
– I Gede Adi Putra
May 7 at 9:05
add a comment |
$result = $request->all();
$created = Your Model::create([Your Data For Table 1]);
if($created)
foreach($request->tb_detail_po as $details)
Your Model2::create([Your Detail Data For Table 2]);
add a comment |
$result = $request->all();
$created = Your Model::create([Your Data For Table 1]);
if($created)
foreach($request->tb_detail_po as $details)
Your Model2::create([Your Detail Data For Table 2]);
add a comment |
$result = $request->all();
$created = Your Model::create([Your Data For Table 1]);
if($created)
foreach($request->tb_detail_po as $details)
Your Model2::create([Your Detail Data For Table 2]);
$result = $request->all();
$created = Your Model::create([Your Data For Table 1]);
if($created)
foreach($request->tb_detail_po as $details)
Your Model2::create([Your Detail Data For Table 2]);
answered Mar 26 at 10:23
Thatoe AungThatoe Aung
571 silver badge9 bronze badges
571 silver badge9 bronze badges
add a comment |
add a comment |
Try to use **JSON_DECODE($data)** OR **JSON_ENCODE($data)**
add a comment |
Try to use **JSON_DECODE($data)** OR **JSON_ENCODE($data)**
add a comment |
Try to use **JSON_DECODE($data)** OR **JSON_ENCODE($data)**
Try to use **JSON_DECODE($data)** OR **JSON_ENCODE($data)**
answered Mar 26 at 12:30
HashanHashan
245 bronze badges
245 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354187%2fhow-to-save-an-array-data-in-json-using-laravel-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you created these databases schemas already? Are you using models?
– thisiskelvin
Mar 26 at 9:57
Not sure what the question is? Do you need help with the database schema? How to deal with data and converting them to easy to work with arrays or collections? Do you need help with the Eloquent models? Do you need help with everything above? Then how did you manage to make create.blade.php work? I have a ton of questions.
– Kerel
Mar 26 at 12:40
@thisiskelvin yes I already create the database schema, I want to save data to table PO, and then table details_PO that related to table PO based on id or kode_trx
– I Gede Adi Putra
Mar 27 at 5:08