0

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';
}
3
  • 3
    Where you are sending $issue to view? Commented Dec 17, 2019 at 10:27
  • /issue to which action. Commented Dec 17, 2019 at 10:28
  • The code above doesn't send the Issue to the view. Is this the right code, or haven't you read the documentation? Also, issue is singular (enkelvoudig) and issues is plural (meervoud). The foreach loop should be @foreach ($issues as $issue). Commented Dec 17, 2019 at 10:35

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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);



     }

 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.