GEOFFREY MWANGI GEOFFREY MWANGI - 3 years ago 174
PHP Question

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.

Answer Source

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()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download