view tables
This commit is contained in:
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Article;
|
||||
use DateTime;
|
||||
|
||||
@@ -588,4 +589,57 @@ class ArticleController extends Controller
|
||||
|
||||
}
|
||||
|
||||
function showTableContent($tableName, $recordCount)
|
||||
{
|
||||
// Verifica se la tabella esiste
|
||||
if (!Schema::hasTable($tableName)) {
|
||||
return "La tabella '$tableName' non esiste.";
|
||||
}
|
||||
|
||||
// Ottieni tutti i campi della tabella
|
||||
$columns = Schema::getColumnListing($tableName);
|
||||
|
||||
// Recupera i record dalla tabella
|
||||
$records = DB::table($tableName)->take($recordCount)->get();
|
||||
|
||||
// Se non ci sono record, restituisci un messaggio
|
||||
if ($records->isEmpty()) {
|
||||
return "Nessun record trovato nella tabella '$tableName'.";
|
||||
}
|
||||
|
||||
// Prepara l'output in formato tabellare
|
||||
$output = "<table border='1'><thead><tr>";
|
||||
|
||||
// Intestazioni della tabella
|
||||
foreach ($columns as $column) {
|
||||
$output .= "<th>$column</th>";
|
||||
}
|
||||
$output .= "</tr></thead><tbody>";
|
||||
|
||||
// Righe dei dati
|
||||
foreach ($records as $record) {
|
||||
$output .= "<tr>";
|
||||
foreach ($columns as $column) {
|
||||
$output .= "<td>" . ($record->$column ?? 'NULL') . "</td>";
|
||||
}
|
||||
$output .= "</tr>";
|
||||
}
|
||||
|
||||
$output .= "</tbody></table>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function showTableByName($tableName, $numrec)
|
||||
{
|
||||
|
||||
// Usa la funzione showTableContent per ottenere i dati in formato tabellare
|
||||
$tableContent = $this->showTableContent($tableName, $numrec);
|
||||
|
||||
// Passa i dati alla vista
|
||||
return view('article.info', [
|
||||
'tableName' => $tableName,
|
||||
'tableContent' => $tableContent
|
||||
]);
|
||||
}
|
||||
}
|
||||
19
resources/views/info.blade.php
Normal file
19
resources/views/info.blade.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Articoli Venduti</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container mt-4">
|
||||
<h1>Mostra Tabella: {{ $tableName }}</h1>
|
||||
|
||||
{!! $tableContent !!}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -6476,3 +6476,4 @@ Route::get('/view-fatturati-by-idarticolo/{idarticolo}', [ArticleController::cla
|
||||
Route::get('/article-test', [ArticleController::class, 'test']);
|
||||
Route::get('/view-info-articolo/{idarticolo}', [ArticleController::class, 'showInfoArticolo']);
|
||||
|
||||
Route::get('/view-table/{tableName}/{numrec}', [ArticleController::class, 'showInfoArticolo']);
|
||||
|
||||
Reference in New Issue
Block a user