laravel log view 表示しない
Q&A
解決したいこと
laravelのlogを表示できるようにしたい。
(login.blade.phpのバリデーションのメッセージのHTMLが、表示しないため、この原因を突き止めるため)
AuthControllerで、デバッグのコードを記述して、
バリデーションのメッセージが、
セッションに格納されてるかをテストするため、
AuthControllerで、デバッグのコードを記述してるが、
src\storage\logs\laravel.logには、表示されてない
AuthenticatedRequestで、設定した、バリデーションのエラーメッセージを
login.blade.php で表示したいが、できない
発生している問題・エラー
[2024-02-20 18:11:44] local.ERROR: There are no commands defined in the "cacche" namespace.
Did you mean this?
cache {"exception":"[object] (Symfony\\Component\\Console\\Exception\\NamespaceNotFoundException(code: 0): There are no commands defined in the \"cacche\" namespace.
Did you mean this?
cache at /var/www/vendor/symfony/console/Application.php:650)
[stacktrace]
#0 /var/www/vendor/symfony/console/Application.php(701): Symfony\\Component\\Console\\Application->findNamespace('cacche')
#1 /var/www/vendor/symfony/console/Application.php(259): Symfony\\Component\\Console\\Application->find('cacche:clear')
#2 /var/www/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#3 /var/www/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 /var/www/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#6 {main}
"}
コマンドのエラーは記録されるが、デバッグは記録されてない。
該当するソースコード
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use App\Http\Requests\AuthenticatedRequest;
use App\Models\User;
class AuthController extends Controller
{
public function index()
{
return view('rest');
}
//1/24 20:30 修正
public function loginView()
{
return view('auth.login');
}
public function rest()
{
return view('rest');
}
public function store(AuthenticatedRequest $request)
{
//バリデーションを通過したデータを取得
$validatedData = $request->validated();
// エラーがある場合、ログに記録
if ($errors = $request->session()->get('errors')) {
Log::error('バリデーションエラー:', $errors->all());
}
//ユーザーをDBに保存
$user = User::create([
'email' => $validatedData['email'],
'password' => bcrypt($validatedData['password']),
]);
//ログイン処理
//auth()->login($user);
//リダレイクト
return redirect()->route('rest');
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AuthenticatedRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|string|email',
'password' => 'required|string|min:8|max:191',
];
}
public function messages()
{
return [
'email.required' => 'メールアドレスは入力必須です。',
'email.string' => 'メールアドレスは文字列である必要があります。',
'email.email' => 'メールアドレスの形式が不正です。',
'password.required' => 'パスワードは入力必須です。',
'password.string' => 'パスワードは文字列である必要があります。',
'password.min' => 'パスワードは8文字以上である必要があります。',
'password.max' => 'パスワードは191文字以内で入力してください。',
];
}
}
@extends('layouts.main')
@section('css')
<link rel="stylesheet" href="{{ asset('css/authen.css') }}">
@endsection
@section('content')
<div class="content">
<h2>ログイン</h2>
<form action="/login" method="post">
@csrf
<div class="form-group">
<input type="email" name="email" placeholder="メールアドレス" value="{{ old('email') }}">
@error('email')
<div class="form-error">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<input type="password" name="password" placeholder="パスワード">
@error('password')
<div class="form-error">{{ $message }}</div>
@enderror
</div>
<button class="button-submit" type="submit">ログイン</button>
</form>
<p>アカウントを""お持ちでない方はこちらから</p>
<a class="register__button-submit" href="/register">会員登録</a>
</div>
@endsection
自分で試したこと
logが表示しない
⓵sudo chmod -R 777 . 権限変更
⓶Envファイルを、LOG_LEVEL=debugにする
⓷.env ファイルで LOG_CHANNEL=single と設定
⓸エラーがある場合、ログに記録
if ($errors = $request->session()->get('errors')) {
Log::error('バリデーションエラー:', $errors->all());
}
⓹Laravel プロジェクトを再構築
Laravel プロジェクトを再構築する
プロジェクトの vendor ディレクトリを削除してから composer install を実行
バリデーションのメッセージ表示しない
⓵これを入ってることをチェック
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
⓶
'locale' => 'ja',に設定
⓷
@error('')
{{ $message }}
@enderror
で表示を試みた。
GIT HUBのコード
追加修正 バリデーションルールを設定しない状態で、storeメソッドが実行
public function store(Request $request)
{
// ログ出力
Log::info('storeメソッドが実行されました。');
// ユーザーをDBに保存
$user = User::create([
'email' => $request->input('email'),
'password' => bcrypt($request->input('password')),
]);
// リダイレクト
return redirect()->route('rest');
}
2024-02-20 18:11:44からlogが、記録されてない
[2024-02-20 18:11:44] local.ERROR: There are no commands defined in the "cacche" namespace.
Did you mean this?
cache {"exception":"[object] (Symfony\\Component\\Console\\Exception\\NamespaceNotFoundException(code: 0): There are no commands defined in the \"cacche\" namespace.
Did you mean this?
cache at /var/www/vendor/symfony/console/Application.php:650)
[stacktrace]
#0 /var/www/vendor/symfony/console/Application.php(701): Symfony\\Component\\Console\\Application->findNamespace('cacche')
#1 /var/www/vendor/symfony/console/Application.php(259): Symfony\\Component\\Console\\Application->find('cacche:clear')
#2 /var/www/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#3 /var/www/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 /var/www/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#6 {main}
"}
root@4739c49087e0:/var/www# php artisan route:list
Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
+--------+----------+------------------------------------------+---------------------------------+-----------------------------------------------------------------------------------+-----------------------------------------------------------+
| Domain | Method | URI | Name | Action
| Middleware |
+--------+----------+------------------------------------------+---------------------------------+-----------------------------------------------------------------------------------+-----------------------------------------------------------+
| | GET|HEAD | / | | App\Http\Controllers\AuthController@index | web |
| | | | |
| App\Http\Middleware\Authenticate |
| | GET|HEAD | _debugbar/assets/javascript | debugbar.assets.js | Barryvdh\Debugbar\Controllers\AssetController@js | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | | | |
| Closure |
| | GET|HEAD | _debugbar/assets/stylesheets | debugbar.assets.css | Barryvdh\Debugbar\Controllers\AssetController@css | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | | | |
| Closure |
| | DELETE | _debugbar/cache/{key}/{tags?} | debugbar.cache.delete | Barryvdh\Debugbar\Controllers\CacheController@delete | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | | | |
| Closure |
| | GET|HEAD | _debugbar/clockwork/{id} | debugbar.clockwork | Barryvdh\Debugbar\Controllers\OpenHandlerController@clockwork | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | | | |
| Closure |
| | GET|HEAD | _debugbar/open | debugbar.openhandler | Barryvdh\Debugbar\Controllers\OpenHandlerController@handle | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | | | |
| Closure |
| | GET|HEAD | api/user | | Closure
| api |
| | | | |
| App\Http\Middleware\Authenticate:sanctum |
| | POST | attendance | | App\Http\Controllers\WorkController@store | web |
| | GET|HEAD | attendance | attendance.index | App\Http\Controllers\WorkController@index | web |
| | GET|HEAD | attendance-day | attendance.index | App\Http\Controllers\WorkController@index | web |
| | GET|HEAD | attendance/search | | App\Http\Controllers\WorkController@search | web |
| | GET|HEAD | dates/search | dates.search | App\Http\Controllers\WorkController@search | web |
| | POST | end-break | endBreak | App\Http\Controllers\WorkController@endBreak | web |
| | POST | end-brek | | App\Http\Controllers\WorkController@endBrerk | web |
| | POST | end-work | endWork | App\Http\Controllers\WorkController@endWork | web |
| | GET|HEAD | forgot-password | password.request | Laravel\Fortify\Http\Controllers\PasswordResetLinkController@create | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | POST | forgot-password | password.email | Laravel\Fortify\Http\Controllers\PasswordResetLinkController@store | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | GET|HEAD | login | login | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@create | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | POST | login | | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@store | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | | | |
| Illuminate\Routing\Middleware\ThrottleRequests:login |
| | POST | logout | logout | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@destroy | web |
| | GET|HEAD | next-page | nextPage | App\Http\Controllers\WorkController@nextPage | web |
| | GET|HEAD | previous-page | previousPage | App\Http\Controllers\WorkController@previousPage | web |
| | GET|HEAD | register | register | App\Http\Controllers\RegisteredUserController@showRegistrationForm | web |
| | POST | register | | Laravel\Fortify\Http\Controllers\RegisteredUserController@store | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | POST | reset-password | password.update | Laravel\Fortify\Http\Controllers\NewPasswordController@store | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | GET|HEAD | reset-password/{token} | password.reset | Laravel\Fortify\Http\Controllers\NewPasswordController@create | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | GET|HEAD | rest | rest | App\Http\Controllers\WorkController@create | web |
| | GET|HEAD | sanctum/csrf-cookie | | Laravel\Sanctum\Http\Controllers\CsrfCookieController@show | web |
| | POST | start-break | startBreak | App\Http\Controllers\WorkController@startBreak | web |
| | GET|HEAD | start-work | startWork | App\Http\Controllers\WorkController@startWork | web |
| | | | |
| App\Http\Middleware\Authenticate |
| | GET|HEAD | two-factor-challenge | two-factor.login | Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController@create | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | POST | two-factor-challenge | | Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController@store | web |
| | | | |
| App\Http\Middleware\RedirectIfAuthenticated:web |
| | | | |
| Illuminate\Routing\Middleware\ThrottleRequests:two-factor |
| | GET|HEAD | user/confirm-password | | Laravel\Fortify\Http\Controllers\ConfirmablePasswordController@show | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | POST | user/confirm-password | password.confirm | Laravel\Fortify\Http\Controllers\ConfirmablePasswordController@store | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | GET|HEAD | user/confirmed-password-status | password.confirmation | Laravel\Fortify\Http\Controllers\ConfirmedPasswordStatusController@show | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | POST | user/confirmed-two-factor-authentication | two-factor.confirm | Laravel\Fortify\Http\Controllers\ConfirmedTwoFactorAuthenticationController@store | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | PUT | user/password | user-password.update | Laravel\Fortify\Http\Controllers\PasswordController@update | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | PUT | user/profile-information | user-profile-information.update | Laravel\Fortify\Http\Controllers\ProfileInformationController@update | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | POST | user/two-factor-authentication | two-factor.enable | Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController@store | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | DELETE | user/two-factor-authentication | two-factor.disable | Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController@destroy | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | GET|HEAD | user/two-factor-qr-code | two-factor.qr-code | Laravel\Fortify\Http\Controllers\TwoFactorQrCodeController@show | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | GET|HEAD | user/two-factor-recovery-codes | two-factor.recovery-codes | Laravel\Fortify\Http\Controllers\RecoveryCodeController@index | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | POST | user/two-factor-recovery-codes | | Laravel\Fortify\Http\Controllers\RecoveryCodeController@store | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
| | GET|HEAD | user/two-factor-secret-key | two-factor.secret-key | Laravel\Fortify\Http\Controllers\TwoFactorSecretKeyController@show | web |
| | | | |
| App\Http\Middleware\Authenticate:web |
| | | | |
| Illuminate\Auth\Middleware\RequirePassword |
+--------+----------+------------------------------------------+---------------------------------+-----------------------------------------------------------------------------------+-----------------------------------------------------------+
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Http\Requests\RegisterRequest;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use Illuminate\Support\Facades\Validator;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::registerView(function () {
return view('auth.register');
});
Fortify::loginView(function () {
return view('auth.login');
});
RateLimiter::for('login', function (Request $request) {
$email = (string) $request->email;
return Limit::perMinute(10)->by($email . $request->ip());
});
}
}
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisteredUserController;
use App\Http\Controllers\WorkController;
use App\Http\Controllers\AuthController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/rest', [WorkController::class, 'create'])->name('rest');
//Route::post('/register', [RegisteredUserController::class, 'store']);
//2/16 16:20
//Route::get('/register', function () {
// return view('auth.register');
//})->name('register');
Route::get('/register', [RegisteredUserController::class, 'showRegistrationForm'])->name('register');
Route::post('/attendance', [WorkController::class, 'store']);
Route::get('/start-work', [WorkController::class, 'startWork'])->name('startWork')->middleware('auth');
Route::post('/end-work', [WorkController::class, 'endWork'])->name('endWork');
Route::post('/start-break', [WorkController::class, 'startBreak'])->name('startBreak');
Route::post('/end-break', [WorkController::class, 'endBreak'])->name('endBreak');
Route::get('/next-page', function () {
return view('work_time');
})->name('work.time');
Route::get('/attendance', [WorkController::class, 'index'])->name('attendance.index');
Route::get('/previous-page', [WorkController::class, 'previousPage'])->name('previousPage');
Route::get('/next-page', [WorkController::class, 'nextPage'])->name('nextPage');
Route::get('/attendance/search', [WorkController::class, 'search']);
Route::get('/dates/search', 'WorkController@search')->name('dates.search');
Route::get('/attendance-day', [WorkController::class, 'index'])->name('attendance.index');
//ログアウト
//1/24 16:30修正(ログイン)
//Route::get('/login', [AuthController::class, 'loginView']);
//1/25 16:10 打刻画面(ホーム)
//Route::get('/', [AuthController::class, 'rest']);
//2/24 storeが機能しないため変更(rest→index)
Route::middleware('auth')->group(function () {
Route::get('/', [AuthController::class, 'index']);
});
//休憩開始、休憩終了2/5
Route::post('/start-break', [WorkController::class, 'startBreak'])->name('startBreak');
Route::post('/end-brek', [WorkController::class, 'endBrerk']);
//2/27 Authenticated.Requestのバリデーションのエラー表示はAuthControllerのstoreアクションのルーティングが抜けてたため
Route::post('/login', [AuthController::class, 'store']);