You need to also show the code where you are calling the audit function.
However, to answer your question blindly, why not call it in the controller for your specific route?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there! I made an Audit and it's working fine. But here is my problem. It's saving every single move my users make. I just want to save when they access an specific route For example I have the routes: /xxx /xxx1 /xxx2 /xxx3 I want my Audit only to make records about the /xxx3 url. Only when my user access /xxx3 then save into my DB
This is my model if it has any use:
use Illuminate\Database\Eloquent\Model;
class Audit extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id', 'method', 'path', 'query', 'userAgent', 'ip', 'device' , 'platform', 'browser' , 'isDesktop', 'isMobile' , 'isPhone' , 'isTablet'
];
public function user ()
{
return $this->belongsTo(User::class);
}
/**
* Get online users
*
* @param int $min
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function online ($min = 3)
{
return $this->select('user_id')
->where('audits.created_at', '>=', Carbon::now()->subMinutes($min)->toDateTimeString())
->distinct('user_id')
->with('user')
->get()->map(function ($item) {
return $item->user;
});
}
}
Please or to participate in this conversation.