Matt Pierce
Matt Pierce

Reputation: 805

Laravel Model Delete Single Record

I'm having trouble getting a chained query to work for deleting a single record in 2 different columns in the user model. On submit, I want to delete the user's record in column A and column B only, nothing else.

DB::table('users')
    ->where('id', Auth::user()->id)
    ->select('column_A')->delete()
    ->select('column_B')->delete()
    ->update([
        'column_A' => 'value',
    ]);

This actually deletes that user's entire record. I have also tried substituting select for value and then I'll get the error:

calling delete() on string

Thanks!

Upvotes: 1

Views: 1282

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

Try something like this:

DB::table('users')
    ->where('id', Auth::user()->id)
    ->update([
        'column_A' => '',
        'column_B' => ''
    ]);

I can use delete() only to delete whole rows, but not some information in that row.

Upvotes: 1

Related Questions