Неопределенная переменная: Employess - PullRequest
0 голосов
/ 08 мая 2019

я хочу показать галерею изображений на странице пользователя

это мой код от ImageUserController

function list(){
    $employees['img_user'] = ImageUser::where('user_id', Auth::user()->id)->get();

    return view('ukm.index', $employees);
}

и этот мой код от UserContoller

public function list()
{
    $employees = ImageUser::all();
    $ukm    = Ukm::all();

    return view('/ukm/index', compact( 'employees', 'ukm'));
}

это мой маршрут

Route::get('/ukm/index', 'ImageUserController@list');

и этот мой код на ukm/index.blade.php

table class="table table-stripped table-bordered">
        <thead class="thead-dark">
          <tr>
            <th scope="col">ID</th>
            <th scope="col">Name</th>
            <th scope="col">Description</th>
            <th scope="col">Image</th>
            <th scope="col">Edit</th>
            <th scope="col">Delete</th>
          </tr>
        </thead>
        <tbody>
        @foreach ($employees as $employee)
          <tr>
            <th scope="row">{{ $employee->id }}</th>
            <td>{{ $employee->name }}</td>
            <td>{{ $employee->description }}</td>
            <td><img src="{{ asset('uploads/employee/' . $employee->image) }}" width="150px;" height="100px;" alt="Image"></td>
            <td><a href="/img_user/editimage/{{ $employee->id }}" class="btn btn-success">Edit</a></td>
            <td><a href="/img_user/deleteimage/{{ $employee->id }}" class="btn btn-danger">Delete</a></td>
          </tr>
        @endforeach
        </tbody>
      </table>

я получаю эту ошибку: Undefined variable: employees

Ответы [ 2 ]

1 голос
/ 08 мая 2019

В вашем ImageUserController list() методе,

function list(){
    $employees = ImageUser::where('user_id', Auth::user()->id)->get();

    return view('ukm.index', compact('employees'));
}
1 голос
/ 08 мая 2019

Вы фактически не передаете массив в представление

return view('ukm.index')->with('employees', $employees); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...