Y.Futekov
Y.Futekov

Reputation: 544

Laravel DB Facade BadMethodCallException

I'm trying to implement insertOrIgnore method from the Laravel DB Facade, here's a link to the docs + explanation snippet: https://laravel.com/docs/5.8/queries#inserts

The insertOrIgnore method will ignore duplicate record errors while inserting records into the database:

DB::table('users')->insertOrIgnore([
    ['id' => 1, 'email' => '[email protected]'],
    ['id' => 2, 'email' => '[email protected]']
]);

And here's the piece of code that produces the error (it works with regular insert())

if ($datetime->format('H:i') >= '05:50' && $datetime->format('H:i') <= '07:10') {
    DB::table('attendanceTable')->insertOrIgnore(['user_id' => $request->loggedUserId, 'day' => $datetime,  'shift_id' => $Shifts->id, 'created_at' => $datetime, 'updated_at' => $datetime]);

Here's the error that Laravel's Telescope produces

Call to undefined method Illuminate\Database\Query\Builder::insertOrIgnore()

Can someone point out what i'm doing wrong, or atleast give me a hint? Thanks in advance!

Upvotes: 1

Views: 1458

Answers (1)

Hiroshi Suda
Hiroshi Suda

Reputation: 36

I had the same error, and it turned out to be because I was on laravel version 5.8.32, and insertOrIgnore was added in version 5.8.33.

Running composer update resolved the issue.

Upvotes: 2

Related Questions