duankuai6586 2018-01-23 05:32
浏览 43
已采纳

如何修复未定义的变量:视图刀片雄辩的laravel 5.3中的产品

I didn't know why undefined variable, I've made controller, model and view. I've included the compact in the controller for the variable.

this is my controller

public function product(){
    $products = Product::all();
    // print_r($products);
    return view('views.product', compact('products'));
}

model

class Product extends Model{
    protected $fillable = ['product_name', 'price', 'kategori'];
}

and view

@foreach ($Products as $post)
    <tr>
        <td>{{$post->product_name}}</td>
    </tr>
@endforeach

route

Route::get('/product', 'AdminController@product')->name('Product');

Please help me I don't know why this undefined variable, cause I've included compact in my controller

  • 写回答

2条回答 默认 最新

  • donglian1384 2018-01-23 05:35
    关注

    It's a typo mistake. Edit your view file. I think it will work.

    //$products instead of $Products 
    @foreach ($products as $post)
    <tr>
       <td>{{$post->product_name}}</td>
    </tr>
    @endforeach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何实现从tello无人机上获取视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决