Can I update a table using model collection?

|
natghi2010 2021-01-31 17:00:44
2021-01-31 16:30:01
Hi. Can I update a table using model collection? I mean does update method work or not?

$object = Model::whereId($id)->first();

Can I run $object->update()?

are you updating group/single record. im confused by your example

profsr123 2021-01-31 17:04:15
“title”:”2″,”type”:”jhhjj”,”oldprice”:”111″,”newprice”:”6″,”type00″:”jhhjj,l,”,”oldprice00″:”11133″,”newprice00″:”6262″,”type0″:”jhhjjkk,”,”oldprice0″:”11661″,”newprice0″:”6655″,
profsr123 2021-01-31 17:04:36
How to insert this type of values in table
profsr123 2021-01-31 17:04:47
Anybody please help
profsr123 2021-01-31 17:05:00
I am giving my names as
profsr123 2021-01-31 17:05:29
title ,type,oldprice,newprice
2021-01-31 17:07:55
natghi2010 2021-01-31 17:00:44
are you updating group/single record. im confused by your example

Yes. I’m updating a single record

2021-01-31 17:08:30
natghi2010 2021-01-31 16:59:58
maybe

Surely: doesn’t work

profsr123 2021-01-31 17:09:02
profsr123 2021-01-31 17:04:15
“title”:”2″,”type”:”jhhjj”,”oldprice”:”111″,”newprice”:”6″,”type00″:”jhhjj,l,”,”oldprice00″:”11133″,”newprice00″:”6262″,”type0″:”jhhjjkk,”,”oldprice0″:”11661″,”newprice0″:”6655″,

Anybody please help

natghi2010 2021-01-31 17:09:18
2021-01-31 17:08:30
Surely: doesn’t work

what are the values you are trying to insert

2021-01-31 17:09:35
natghi2010 2021-01-31 17:09:18
what are the values you are trying to insert

Some fields in the table

natghi2010 2021-01-31 17:09:38
profsr123 2021-01-31 17:04:15
“title”:”2″,”type”:”jhhjj”,”oldprice”:”111″,”newprice”:”6″,”type00″:”jhhjj,l,”,”oldprice00″:”11133″,”newprice00″:”6262″,”type0″:”jhhjjkk,”,”oldprice0″:”11661″,”newprice0″:”6655″,

what type of values

natghi2010 2021-01-31 17:09:48
2021-01-31 17:09:35
Some fields in the table

you didnt specify this

2021-01-31 17:10:05
profsr123 2021-01-31 17:04:15
“title”:”2″,”type”:”jhhjj”,”oldprice”:”111″,”newprice”:”6″,”type00″:”jhhjj,l,”,”oldprice00″:”11133″,”newprice00″:”6262″,”type0″:”jhhjjkk,”,”oldprice0″:”11661″,”newprice0″:”6655″,

It seems it’s json. just parse it first

natghi2010 2021-01-31 17:10:24
2021-01-31 17:10:05
It seems it’s json. just parse it first

laravel autoparses?

natghi2010 2021-01-31 17:10:40
or json_decode($values,true)?
2021-01-31 17:10:44
natghi2010 2021-01-31 17:10:24
laravel autoparses?

Nope. json_decode

2021-01-31 17:11:08
2021-01-31 17:10:44
Nope. json_decode

When you converted the data to an array:

…->where($CONDITION)->update(json_decode($data));

2021-01-31 17:11:48
natghi2010 2021-01-31 17:09:48
you didnt specify this

I know. The whole point is the update method. It doesn’t matter what I’m trying to update

2021-01-31 17:12:04
the update method can’t be accessed like this
natghi2010 2021-01-31 17:15:00
2021-01-31 17:12:04
the update method can’t be accessed like this

model::whereIn(‘id’, $ids)->update($request->all());

natghi2010 2021-01-31 17:15:13
whee ids is an array
2021-01-31 17:15:24
natghi2010 2021-01-31 17:15:00
model::whereIn(‘id’, $ids)->update($request->all());

I know this one works, but I didn’t have the model.

2021-01-31 17:15:35
I would my code be a bit simpler.
2021-01-31 17:15:58
I ran this code:

DB::table($collection->getTable())->whereId($collection->id)->update($data);

2021-01-31 17:17:26
natghi2010 2021-01-31 17:15:13
whee ids is an array

Thanks anyway 🙂 There is NOT ANY OTHER was.

natghi2010 2021-01-31 17:21:41
2021-01-31 17:15:58
I ran this code:

DB::table($collection->getTable())->whereId($collection->id)->update($data);

this is probably the best. didnt know there was such thing as getTable method

2021-01-31 17:22:04
natghi2010 2021-01-31 17:21:41
this is probably the best. didnt know there was such thing as getTable method

Yeah. It’s very useful in such cases.

natghi2010 2021-01-31 17:29:27
2021-01-31 17:22:04
Yeah. It’s very useful in such cases.

random question
how deal with combo box with laravel

natghi2010 2021-01-31 17:29:52
when trying to preselect the combo box
2021-01-31 17:30:35
natghi2010 2021-01-31 17:29:27
random question
how deal with combo box with laravel

Is that some kind of data structure? I’ve seen combo boxes just in Qt framework lol

natghi2010 2021-01-31 17:30:50
no i mean <select></select>
natghi2010 2021-01-31 17:31:27
writing if statements just sucks to preselect
2021-01-31 17:34:03
natghi2010 2021-01-31 17:29:52
when trying to preselect the combo box

If it’s something like XML, I recommend dom-crawler package. It’s great.

https://packagist.org/packages/symfony/dom-crawler

symfony/dom-crawler – Packagistpackagist.org
Eases DOM navigation for HTML and XML documents
2021-01-31 17:35:06
Honestly didn’t get what you mean lol I’ve seen combo boxes just in desktop gui programs.
|