我想创建一个日志来通知新用户的注册,问题出在行中,我想创建一个日志来通知新用户的注册,问题出在$log_message = Log::channel('logRegisterUser')->info("{$name_user} registered using the IP {$ip_user} in {$data}.");
行中,当放置在dd()
中时显示为null
。在'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);
}
1条答案
按热度按时间mhd8tkvw1#
Log-〉info()不返回值,而是先在变量中写入消息,然后将其传递给Logger: