I am wanting to create a log that informs the registration of a new user, the problem is in the line, i'm wanting to create a log that informs the registration of a new user, the problem is in the line $log_message = Log::channel('logRegisterUser')->info("{$name_user} registered using the IP {$ip_user} in {$data}.");
which when placed in a dd()
is revealed as null
. With this creating error at line 'description_log' => $log_message,
.
logging.php
'logRegisterUser' => [
'driver' => 'single',
'path' => storage_path('logs/logRegisterUser.log'),
'level' => 'debug',
],
RegisteredUserController.php
public function __construct()
{
$this->logModel = new LoggingModel();
}
public function create()
{
return view('auth.register');
}
public function store(Request $request)
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
event(new Registered($user));
$date = Carbon::now()->format('d/m/Y H:i:s');
$name_user = $user->name;
$ip_user = request()->ip();
$log_message = Log::channel('logRegisterUser')->info("{$name_user} registered using the IP {$ip_user} in {$data}.");
$this->logModel->create([
'description_log' => $log_message,
'relation' => '',
]);
Auth::login($user);
return redirect(RouteServiceProvider::HOME);
}
Log::info()
doesn't return a value. What are you expecting? "{$name_user} registered using the IP {$ip_user} in {$data}."
Log::info()
and into your logModel Log->info() does not return a value. Instead write message in your variable first and then pass it to your Logger :
$log_message = "{$name_user} registered using the IP {$ip_user} in {$data}.";
Log::channel('logRegisterUser')->info($log_message);