I'm refactoring all my DB Access related to my User Model in my Laravel app implementing Repositories.
So, now, all my DB Access ( I use Eloquent ) go through my UserRepository.
But I still have some eloquent operations in my model User:
class User extends Model{
....
public static function boot()
{
parent::boot();
static::creating(function ($user) {
$softDeletedUser = User::onlyTrashed()->where('email', '=', $user->email)->first();
if ($softDeletedUser != null) {
$softDeletedUser->restore();
return false;
} else {
$user->token = str_random(30);
if ($user->country_id == 0) {
$user->addGeoData();
}
}
return true;
});
I don't know what to do with that because:
- It's about my User Model, not my Controller
- It is a static method, so I don't know how to pass $this with (use)
- I guess there is something wrong with that....
So... What should I do in this situation?