首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义变量:就业

未定义变量:就业
EN

Stack Overflow用户
提问于 2019-05-08 12:21:54
回答 2查看 78关注 0票数 0

我想在用户页面显示图片库

这是我来自ImageUserController的代码

代码语言:javascript
复制
function list(){
    $employees['img_user'] = ImageUser::where('user_id', Auth::user()->id)->get();

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

这是我来自UserContoller的代码

代码语言:javascript
复制
public function list()
{
    $employees = ImageUser::all();
    $ukm    = Ukm::all();

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

这是我的路线

代码语言:javascript
复制
Route::get('/ukm/index', 'ImageUserController@list');

这是我在ukm/index.blade.php的代码

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-08 12:26:30

实际上,您并没有将数组传递给视图

代码语言:javascript
复制
return view('ukm.index')->with('employees', $employees); 
票数 1
EN

Stack Overflow用户

发布于 2019-05-08 12:29:28

在您ImageUserController list()方法中,

代码语言:javascript
复制
function list(){
    $employees = ImageUser::where('user_id', Auth::user()->id)->get();

    return view('ukm.index', compact('employees'));
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56033503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档