将数据插入数据库后,无法在Laravel中显示数据库中的数据
我能够在Laravel中将数据插入到数据库中,但当我试图以表格形式显示数据时,我无法做到——它显示的是未定义的路由[stock_edit]。视图:C:\wamp\www\pump\core\resources\views\dashboard\stock-show.blade.php将数据插入数据库后,无法在Laravel中显示数据库中的数据,laravel,Laravel,我能够在Laravel中将数据插入到数据库中,但当我试图以表格形式显示数据时,我无法做到——它显示的是未定义的路由[stock_edit]。视图:C:\wamp\www\pump\core\resources\views\dashboard\stock-show.blade.php @extends('layouts.dashboard') @section('title', 'All Stock') @section('content') @if(count($stock))
@extends('layouts.dashboard')
@section('title', 'All Stock')
@section('content')
@if(count($stock))
<div class="row">
<div class="col-md-12">
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption font-dark">
</div>
<div class="tools"> </div>
</div>
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th>ID#</th>
<th>Product Name</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($stock as $p)
<tr>
<td>{{ $p->id }}</td>
<td>{{ $p->name }}</td>
<td>{{ $p->price }} </td>
<td>
<a href="{{ route('stock_edit',$p->id) }}" class="btn purple btn-sm"><i class="fa fa-edit"></i> EDIT</a>
<button type="button" class="btn btn-danger btn-sm delete_button"
data-toggle="modal" data-target="#DelModal"
data-id="{{ $p->id }}">
<i class='fa fa-times'></i> DELETE
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div><!-- ROW-->
<div class="text-center">
{!! $stock->render() !!}
</div>
@else
<div class="text-center">
<h3>No Data available</h3>
</div>
@endif
<!-- Modal for DELETE -->
<div class="modal fade" id="DelModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"> <i class='fa fa-trash'></i> Delete !</h4>
</div>
<div class="modal-body">
<strong>Are you sure you want to Delete ?</strong>
</div>
<div class="modal-footer">
<form method="post" action="{{ route('stock_delete') }}" class="form-inline">
{!! csrf_field() !!}
{{ method_field('DELETE') }}
<input type="hidden" name="id" class="abir_id" value="0">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">DELETE</button>
</form>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
$(document).ready(function () {
$(document).on("click", '.delete_button', function (e) {
var id = $(this).data('id');
$(".abir_id").val(id);
});
});
</script>
@endsection
正如我在昨天的提问中所说,我是拉雷维尔的新手,我还不了解环境。在过去的48小时里,我一直在网上寻找帮助,但找不到满意的
这是我的stock-show.blade.php
@extends('layouts.dashboard')
@section('title', 'All Stock')
@section('content')
@if(count($stock))
<div class="row">
<div class="col-md-12">
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption font-dark">
</div>
<div class="tools"> </div>
</div>
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th>ID#</th>
<th>Product Name</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($stock as $p)
<tr>
<td>{{ $p->id }}</td>
<td>{{ $p->name }}</td>
<td>{{ $p->price }} </td>
<td>
<a href="{{ route('stock_edit',$p->id) }}" class="btn purple btn-sm"><i class="fa fa-edit"></i> EDIT</a>
<button type="button" class="btn btn-danger btn-sm delete_button"
data-toggle="modal" data-target="#DelModal"
data-id="{{ $p->id }}">
<i class='fa fa-times'></i> DELETE
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div><!-- ROW-->
<div class="text-center">
{!! $stock->render() !!}
</div>
@else
<div class="text-center">
<h3>No Data available</h3>
</div>
@endif
<!-- Modal for DELETE -->
<div class="modal fade" id="DelModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"> <i class='fa fa-trash'></i> Delete !</h4>
</div>
<div class="modal-body">
<strong>Are you sure you want to Delete ?</strong>
</div>
<div class="modal-footer">
<form method="post" action="{{ route('stock_delete') }}" class="form-inline">
{!! csrf_field() !!}
{{ method_field('DELETE') }}
<input type="hidden" name="id" class="abir_id" value="0">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">DELETE</button>
</form>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
$(document).ready(function () {
$(document).on("click", '.delete_button', function (e) {
var id = $(this).data('id');
$(".abir_id").val(id);
});
});
</script>
@endsection
最后是route.php
/* Stock Route List */
Route::get('stock-create',['as'=>'stock-create','uses'=>'DashboardController@createStock']);
Route::post('stock-create',['as'=>'stock-store','uses'=>'DashboardController@storeStock']);
Route::get('stock-show',['as'=>'stock-show','uses'=>'DashboardController@showStock']);
Route::get('stock-edit/{id}',['as'=>'stock-edit','uses'=>'DashboardController@editStock']);
Route::put('stock-edit/{id}',['as'=>'stock-update','uses'=>'DashboardController@updateStock']);
你的代码有错误
在您的视图中将stock_edit更改为stock edit您在您的stock blade文件中使用href={{route'stock_edit',$p->id},但不在route.php文件中。更改路径::put'stock-edit/{id}',['as'=>'stock-update','uses'=>'DashboardController@updateStock']; 发送::put'stock_edit/{id}',['as'=>'stock-update','uses'=>'DashboardController@updateStock']; 谢谢各位。现在工作。