【发布时间】:2018-04-07 07:00:11
【问题描述】:
“未定义变量:Pro(查看:E:\xampp\htdocs\mypro\resources\views\folder\product.blade.php)”我使用的是laravel 5.6 试图从现有数据库中获取数据。
产品型号
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table='products';
protected $primaryKey = 'p_id';
protected $fillable = ['p_title', 'p_element', 'p_description', 'p_duration', 'p_amount', 'p_startDate', 'p_endDate', 'p_old_price', 'p_new_price', 'p_keyWords', 'p_category', 'p_status', 'prefertime'];
}
产品控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProductController extends Controller
{
public function index()
{
$pro=Product::all();
return view('Folder.product'), compact('pro'));
}
}
Product.blade.php @extends('layouts.app')
@section('content')
<h1>Products</h1>
<table style="width:100%">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
@foreach($Pro as $row)
<td>{{$row['p_id']}}</td>
<td>{{$row['p_title']}}</td>
@endforeach
</tr>
</table>
@endsection
【问题讨论】:
-
return view('Folder'), compact('pro'));