binggle
5 months ago

how to get model id in Eloquent model ?

Posted 5 months ago by binggle

hi

I want to get sum of coins table with where in User Model.

class User extends Model
{

  public function today_charge()
  {
    $self = self::class;

    $sum = DB::table('coins')->where('user_id', $self->id)
        ->where('div', 'charge')->where('status', 'confirmed')->sum('amount');
    return $sum;

  }

}

How can I access self->id ?

Please sign in or create an account to participate in this conversation.