1

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?

5
  • $items would be an array. You need to check and use accordingly. Commented Jun 11, 2017 at 9:29
  • i dont know how to use it so that is why i asked it? Commented Jun 11, 2017 at 9:30
  • Just use like this: @foreach ($items as $item) <div>{{ $item->FIELD_NAME }}</div> @endforeach Commented Jun 11, 2017 at 9:32
  • No sir i just want to called it in that form`s values field.please see the forms value field Commented Jun 11, 2017 at 9:34
  • i mean here input type="text" name="trainee_id" class="form-control" value=" <td>{{ $item->trainee_id }}</td>"> Commented Jun 11, 2017 at 9:34

2 Answers 2

1

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

@foreach ($items as $item)
    <div>{{ $item->trainee_id }}</div>
@endforeach
Sign up to request clarification or add additional context in comments.

4 Comments

how can i called it into above form value attribute?
i mean here input type="text" name="trainee_id" class="form-control" value=" <td>{{ $item->trainee_id }}</td>">
<input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
@Dasun it's impossible if you're using controller method you've shown. Check routes file and make sure you're using correct controller method.
0

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

5 Comments

so that it gives error called Undefined variable: items (View: C:\xampp\htdocs\Attendance_Management\resources\views\traineeattendance\attendance.blade.php)
yes i saw ,i changed it but still the same error sir.
replace return view('traineeattendance.details', compact('items')); to return view('traineeattendance.details', ['items' => $items]); and run this command in your terminal php artisan cache:clear and php artisan view:clear
make sure, are you using this variable in traineeattendance->details.blade.php page

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.