Reputation: 41
so i'm trying to fetch data from my database into a datatable i got from getbootstrap
but i get the error:
Undefined variable: issue (View: C:\Users...\resources\views\dashboard.blade.php)
below ive listed the code where i use the variable: 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');
}
}
the model dashboard.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Dashboard extends Model
{
protected $table = 'issue';
}
Upvotes: 0
Views: 206
Reputation: 92
You didn't send $issues to blade page, change your DashboardController like this:
<?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);
}
}
Upvotes: 0
Reputation: 241
You should pass the variable to the view.
Lets say you have a HomeController, and want to pass some variable to a view from the controller.
HomeController.php
public function show()
{
$someVariable = "An Awesome Example";
return view('example', [
'someVariable' => $someVariable,
]);
}
example.blade.php
<b>{{ $someVariable }}</b>
You have to pass data to a view. Then inside your view you can show that data to the user. In my example I've created a array with the key someVariable and passed $someVariable to the value of that key.
Inside my view I can then use the key to show the value.
Upvotes: 1