这是我的控制器
public function create(Request $request)
{
$query = $request->input("sql_query");
$submit = $request->input("execute_sql");
$fieldname= "";
$sqls = "";
$outputs = "";
if (isset($submit)) {
if ($query != "") {
$fieldname = str_replace("@name", "Tarpaulin", $query);
$outputs = "SELECT * FROM report_content WHERE field_name = 'Title'";
$sqls = DB::select(DB::raw($outputs));
}
}
//die();
return view('reports.create', compact('fieldtypes', 'json', 'query', 'submit'))
->with('fieldname', $fieldname)
->with('sqls', $sqls)
->with('outputs', $outputs);
}
create.blade.php
<form id="sqlForm" action="{{ url('/reports/create') }}" method="GET">
<div class="col-md-12">
<div class="form-group @if($errors->has('query')) has-error @endif">
<div class="col-md-5">
<textarea rows="7" cols="7" id="sql_query" name="sql_query" class="form-control" required></textarea>
<br>
<button type="submit" class="btn btn-primary" id="execute_sql" name="execute_sql"><i class="fa fa-filter" aria-hidden="true"></i> Filter</button>
</div>
<div class="col-md-5">
<table>
@foreach($sqls as $sql)
<tr id="field-default">
<td>
{{ $sql }}
</td>
</tr>
@endforeach
</table>
</div>
<div class="col-xs-5">
</div>
<div class="col-xs-5">
</div>
</div>
</div>
答案 0 :(得分:1)
htmlentities就在这里:
<td>
{{ $sql }}
</td>
。
$sql
可能是null,undefined或数组。在传递给视图之前尝试调试,或者将行更改为<?php dd($sql) ?>
以调试var。只有字符串可以通过htmlentities转换,这就是{{}}
所做的。
答案 1 :(得分:0)
你通过了#34; sqls&#34;而不是&#34; sql&#34;从您的控制器到您的视图。所以你应该这样做:
<td>
{{ $sqls }}
</td>