I\'m trying to log all actions that users do (login / logout / CRUD) to a logs table in my database, and from what I\'ve seen events look to be the right way to do this.
you can make helper function like that
function LogSystem($table,$action,$custom=null)
{
$table::$action(function ($service) use ($action,$custom){
if( ! is_null($custom))
{
$url='/panel/'.$custom.'/'.$service->id.'/edit';
}
else
{
$url=\Illuminate\Support\Facades\Request::fullUrl();
}
\Illuminate\Support\Facades\DB::table('log_activity')->insert([
'subject' => $action.'::=='.$service->title,
'url' => $url,
'method' => \Illuminate\Support\Facades\Request::method(),
'agent' => \Illuminate\Support\Facades\Request::header('user-agent'),
'ip' => \Illuminate\Support\Facades\Request::ip(),
'created_at'=>\Carbon\Carbon::now(),
'user_id' => auth('admin')->check() ? auth('admin')->user()->id : 1,
]);
//
});
}
Then Go to serviceproviders
LogSystem('\App\Services','created','services');
you Can call this for all croud system for any module you want