index.blade.php文件没有返回任何视图或脚本?

时间:2018-01-09 17:35:59

标签: php laravel model-view-controller laravel-5.5

我正面临一个关于我最近的项目的问题,我试图通过数据库中的表单保存一些日期(这是按预期工作)但当我试图从我的数据库中获取该数据时它没有显示在视图中甚至没有脚本但是相同的代码在另一个视图中工作的任何东西(好像代码甚至不存在)。 code which is supposed to be executed returned view

控制器代码:

 public function index()
    {
        $products = Product::all();
        return view('product.index',compact('products'));

    }

刀片代码:

@include('includes.header')
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12" style="margin: 30px" >
            <table class="table table-bordered col-md-12 table-sm">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>Image</th>
                    <th>Company Name</th>
                    <th>Title</th>
                    <th>Price</th>
                    <th>Status</th>
                    <th>Description</th>
                    <th>Created At</th>
                    <th>Updated At</th>
                </tr>
                </thead>
                <tbody>
                @if($products)
                    @foreach($products as $product)
                        <tr>
                            <td>{{$product->id}}</td>
                            <td><img src="" alt="">{{$product->photo ? $product->photo->file : 'no item photo'}}</td>
                            <td>{{$product->cname}}</td>
                            <td>{{$product->title}}</td>
                            <td>{{$product->price}}</td>
                            <td>{{$product->status == 1 ? "Active" : "Not Active"}}</td>
                            <td>{{$product->description}}</td>
                            <td>{{$product->created_at->diffForHumans()}}</td>
                            <td>{{$product->updated_at->diffForHumans()}}</td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
    </div>

</div>
<!-- /#page-wrapper -->



@include('includes.footer')

1 个答案:

答案 0 :(得分:0)

主要问题是它的行为类似于路径未定义且其视图未设置(实际情况并非如此)。我把它定义为

Route::resource('/admin/product','ProductController');

它正在归还我routes 如果定义了路线并且它没有返回它的视图,那怎么可能呢?

  

我已经为它创建了一个自定义路径和视图,并将它返回给它(index.blade.php)视图,现在它正在工作。