I solved this problem.
If name of table that I'm going to get names of columns and data is 'XXX',
first, I wrote following as code at controller.
public function index(){
....
$columns = DB::select('show columns from XXX);
$contents = DB::table('XXX')->get();
$contents_keys = array_keys($contents->toArray());
foreach($columns as col) {
$contents_data[] = $col->Filed;
}
....
return view('route of view')->with('columns', $columns)
->with('contents_data', $contents_data)
->with('contents', $contents)
->with('contens_keys', $content_keys);
}
and then I wrote code at xx.blade.php on View.
...
@foreach($columns as $column)
@foreach($contents as $item)
@foreach($contents_data as $key)
@endforeach
@endforeach
{{$column->Field}} | @endif
|
---|
{{ $item->$key }} |
....