找不到InvalidArgumentException视图[admin.products.view_products]。在laravel 5.7中

时间:2018-12-06 08:14:08

标签: laravel laravel-5 laravel-5.2

m试图在管理面板中显示数据库记录,并向我显示错误:InvalidArgumentException视图[admin.products.view_products]未找到。有解决方案吗?

我的功能是:

public function viewProducts(){
$products = Product::get();
$products = json_decode(json_encode($products));
//echo "<pre>"; print_r($products); die;
return view('admin.products.view_products')->with(compact('products'));
}

路线为:

  Route::get('/admin/view-products','ProductsController@viewProducts');

这是表格:

    <thead>
        <tr>
          <th>Product ID</th>
          <th>Category ID</th>
          <th>Product Name</th>
          <th>Product Code</th>
          <th>Product Color</th>
          <th>Price</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
        @foreach($products as $product)
        <tr class="gradeX">
          <td>{{ $product->id }}</td>
          <td>{{ $product->category_id }}</td>
          <td>{{ $product->product_name }}</td>
          <td>{{ $product->product_code }}</td>
          <td>{{ $product->product_color }}</td>
          <td>{{ $product->price }}</td>
          <td class="center"><a href="{{ url('/admin/edit-product/'.$product- 
    >id) }}" class="btn 
   btn-primary btn-mini">Edit</a> <a id="delCat" href="{{ url('/admin/delete- 
  product/'.$product->id) }}" class="btn btn-danger btn-mini">Delete</a></td>
        </tr>
        @endforeach

1 个答案:

答案 0 :(得分:0)

您的视图文件必须位于

resources/admin/products directory名为view_products.blade.php

控制器

public function viewProducts(){
    $data['products'] = Product::all();
    return view('admin.products.view_products',$data);
}