Html Laravel中带控制器的模态分析
嘿,朋友们,我正在创建一个简单的模式,向我展示提供商的数据,老实说,这花费了我很多钱;有人能帮我一下吗 模态:Html Laravel中带控制器的模态分析,html,ajax,laravel,modal-dialog,Html,Ajax,Laravel,Modal Dialog,嘿,朋友们,我正在创建一个简单的模式,向我展示提供商的数据,老实说,这花费了我很多钱;有人能帮我一下吗 模态: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal"> <div class="modal-dialog" role="document"> <div class="modal-
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModal">
<div class="modal-dialog"
role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModal">Detalle del Proveedor: </h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-stripped table-bordered table-hover" id="table-detalle-proveedores">
<thead>
<tr>
<th>Nombre</th>
<th>Apellido</th>
<th>Telefono</th>
<th>Email</th>
<th>Dirección</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
控制器的功能
public function item(Request $request)
{
$items = Proveedores::select($request->id);
return json_encode($items);
}
我正在测试一个和其他对象,但我得到的最大值是在控制台中显示一个空对象首先,在javascript中,您将id作为
proveedores\u id
传递,但在控制器中,您尝试使用$request->id
访问它
这可能是一个值得一看的想法
其次,使用justselect
,您将返回一个json编码版本的Builder
要让您的请求实际返回proveStores
的实例,您可以执行以下操作:
public function item(Request $request)
{
$item = Proveedores::findOrFail($request->id);
return compact('item');
}
这也意味着您可以删除success方法中的for
循环,只需使用response.item.*
访问数据即可
function (response) {
console.log(response)
table.html('')
var fila = "<tr>" +
"<td>" + response.item.name + "</td>" +
"<td>" + response.item.last_name + "</td>" +
"<td>" + response.item.tel + "</td>" +
"<td>" + response.item.address + "</td>" +
"</tr>";
table.append(fila);
}
功能(响应){
console.log(响应)
html(“”)
var fila=“”+
“”+response.item.name+“”+
“”+response.item.last_name+“”+
“”+response.item.tel+“”+
“”+response.item.address+“”+
"";
表1.追加(fila);
}
希望这有帮助 find和findorfail之间有什么区别?@basosneo
find
如果不存在,将返回null
findOrFail()
将抛出一个异常,该异常最终将变成404响应。因为我让它与“find”一起工作,因为与“findorfail”一起工作不会work@basosneo这很奇怪,因为findOrFail
只是在幕后使用find
。您收到了什么错误?我没有收到任何东西(既没有错误也没有数据),但我会使用find查找是否收到了供应商的数据
public function item(Request $request)
{
$item = Proveedores::findOrFail($request->id);
return compact('item');
}
function (response) {
console.log(response)
table.html('')
var fila = "<tr>" +
"<td>" + response.item.name + "</td>" +
"<td>" + response.item.last_name + "</td>" +
"<td>" + response.item.tel + "</td>" +
"<td>" + response.item.address + "</td>" +
"</tr>";
table.append(fila);
}