Dasun
Dasun

Reputation: 612

Laravel 5 Undefined variable in view error

I am new to laravel 5.4. I am not able to find a solution to this problem anywhere.

what I am returning $items filtered it gives me an error.

Controller

public function data()
{
    $items = registerdetails::all();
    return view('traineeattendance.details', compact('items'));
}

View

<div class="form-group">
    <label>Trainee ID</label>
    input type="text" name="trainee_id" class="form-control" value=" <td>{{ $item->trainee_id }}</td>">
</div>`

How can I fix this error?

Upvotes: 1

Views: 1089

Answers (2)

Farhad Hossen
Farhad Hossen

Reputation: 273

follow this code:

@foreach ($items as $item)
 <div class="form-group">
    <label>Trainee ID</label>
    <input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
</div>
@endforeach

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Since $items is a collection, you need to iterate over it:

@foreach ($items as $item)
    <div>{{ $item->trainee_id }}</div>
@endforeach

Upvotes: 1

Related Questions