【发布时间】:2019-12-17 10:25:58
【问题描述】:
所以我试图从我的数据库中获取数据到我从 getbootstrap 获得的数据表中
但我得到了错误:
未定义变量:问题(查看:C:\Users...\resources\views\dashboard.blade.php)
下面我列出了我使用变量的代码:问题
dashboard.blade.php
<table id="datatable" class="table table-bordered table-striped table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Issue</th>
<th scope="col">begrootte tijd</th>
<th scope="col">beschrijving</th>
<th scope="col">Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col">#</th>
<th scope="col">Issue</th>
<th scope="col">begrootte tijd</th>
<th scope="col">beschrijving</th>
<th scope="col">Action</th>
</tr>
</tfoot>
<tbody>
@foreach($issue as $issues)
<tr>
<th> {{ $issues->id }} </th>
<th> {{ $issues->iname }} </th>
<th> {{ $issues->begroting }} </th>
<th> {{ $issues->description }} </th>
<th>
<a href="" class="btn btn-success"> START</a>
<a href="" class="btn btn-danger"> STOP</a>
</th>
</tr>
@endforeach
</tbody>
DashboardController.php
<?php
namespace App\Http\Controllers;
use App\Dashboard;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function store(Request $request)
{
$this->validate($request,[
'iname' => 'required',
'begroting' => 'required',
'description' => 'required',
]);
$issue = new Issue;
$issue->iname = $request->input('iname');
$issue->begroting = $request->input('begroting');
$issue->description = $request->input('description');
$issue->save();
return redirect('/issue')->with('success', 'Issue opgeslagen');
}
}
型号 dashboard.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Dashboard extends Model
{
protected $table = 'issue';
}
【问题讨论】:
-
您要将
$issue发送到哪里查看? -
/issue执行哪个操作。 -
上面的代码不会将问题发送到视图。这是正确的代码,还是您没有阅读文档?此外,
issue是单数 (enkelvoudig),issues是复数 (meervoud)。 foreach 循环应该是@foreach ($issues as $issue)。
标签: php laravel variables view