Template System Check in Route on Laravel
ตัวอย่าง System Check ที่ใช้ Prefix Name `check` ในการตรวจสอบการตั้งค่าของระบบ ช่วงที่อยู่ในการพัฒนาระบบ
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Config;
Route::prefix('check')->group(function () {
// Route to check PHP info
Route::get('/phpinfo', function () {
phpinfo();
});
// Route to check Laravel version
Route::get('/version', function () {
return app()->version();
});
// Route to check database connection
Route::get('/database', function () {
try {
DB::connection()->getPdo();
return 'Database connection is successful!';
} catch (\Exception $e) {
return 'Could not connect to the database. Please check your configuration.';
}
});
// Route to check public path
Route::get('/public', function () {
return public_path();
});
// Route to check date and time
Route::get('/time', function () {
return now();
});
// Route to check session locale
Route::get('/session', function () {
return Session::get('locale', 'No locale set in session');
});
// Route to flush all session data
Route::get('/flush-session', function () {
Session::flush();
return 'All session data has been flushed.';
});
// Route to check cache driver
Route::get('/cache', function () {
return config('cache.default');
});
// Route to check storage path
Route::get('/storage', function () {
return Storage::path('/');
});
// Route to check log file path
Route::get('/log-path', function () {
return storage_path('logs/laravel.log');
});
// Route to check environment
Route::get('/environment', function () {
return app()->environment();
});
// Route to check debug mode status
Route::get('/debug', function () {
return config('app.debug') ? 'Debug mode is ON' : 'Debug mode is OFF';
});
// Route to check config cache status
Route::get('/config-cache', function () {
return Cache::has('config') ? 'Config is cached' : 'Config is not cached';
});
// Route to check route cache status
Route::get('/route-cache', function () {
return Cache::has('routes') ? 'Routes are cached' : 'Routes are not cached';
});
// Route to check if storage is writable
Route::get('/storage-writable', function () {
return is_writable(storage_path()) ? 'Storage is writable' : 'Storage is not writable';
});
// Route to check if app key is set
Route::get('/app-key', function () {
return config('app.key') ? 'App key is set' : 'App key is not set';
});
});
Last updated