rei
rei

Reputation: 37

How to only select one column and update it?

I want to only select one column from the database then update only that one column

  DB::table('available_rooms')
  ->where('roomTypeID', '=', $request->session()->get('room_type'))->first()
  ->update(['isAvailable'=> 0]);

With this I'm getting an error

Call to undefined method stdClass::update()

Upvotes: 0

Views: 76

Answers (3)

Garnara Vishal
Garnara Vishal

Reputation: 26

You may try this:

Post::where('id', $id)->update(array('title' => 'asdasd'));

Upvotes: 0

Dhruv Raval
Dhruv Raval

Reputation: 1583

Eloquent style

Create model if you don't created:

AvailableRoom::where('roomTypeID', '=',  $request->session()->get('room_type'))
              ->update(['isAvailable'=> 0])

Upvotes: 1

Sand Of Vega
Sand Of Vega

Reputation: 2416

Use limit() method instead of first():

DB::table('available_rooms')
  ->where('roomTypeID', '=', $request->session()->get('room_type'))->limit(1)
  ->update(['isAvailable'=> 0]);

Upvotes: 0

Related Questions