Geoff
Geoff

Reputation: 6639

Using And where condition in Laravel model

What am trying to do is to use andWhere in my request

$passwordreset =  PasswordResets::where('token', $request->resetcode)
   ->andWhere('created_at','>',Carbon::now()->subHours(2))//error due to and
   ->first();

But the above returns an error.How can i perform this using the Model not DB:table since i would like a standard way of writing my code just by using the model.

Upvotes: 0

Views: 331

Answers (1)

linktoahref
linktoahref

Reputation: 7972

Since Eloquent models are query builders, you should review all of the methods available on the query builder. You may use any of these methods in your Eloquent queries.

$passwordreset =  PasswordResets::where([
                      ['token', $request->resetcode],
                      ['created_at', '>', Carbon::now()->subHours(2)]
                  ])->first();

API Reference where()

Upvotes: 1

Related Questions