所以我正试图从数据库中获取数据到从getbootstrap获得的数据表中
但是我得到了错误:
未定义变量:问题(视图:C:\ Users ... \ resources \ views \ dashboard.blade.php)
在ive下面列出了我使用变量的代码:issue
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';
}
答案 0 :(得分:1)
您应该将变量传递给视图。
假设您有一个HomeController,并希望将一些变量从控制器传递到视图。
HomeController.php
public function show()
{
$someVariable = "An Awesome Example";
return view('example', [
'someVariable' => $someVariable,
]);
}
example.blade.php
<b>{{ $someVariable }}</b>
您必须将数据传递到视图。然后,您可以在视图中向用户显示该数据。在我的示例中,我创建了一个具有键 someVariable 的数组,并将 $ someVariable 传递给该键的值。
然后在我的视图内,我可以使用键显示该值。
答案 1 :(得分:0)
您没有将$ issues发送到刀片页面,请像这样更改DashboardController:
<?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();
$issues=Dashboard::all();
return redirect('/issue')->with('success', 'Issue opgeslagen')
->with('issues',$issues);
}
}