laravel 属性 [id] 在此集合实例上不存在

我无法访问我的admin_table我知道我有,并且在admin_table的路线上有问题,请在我的路线上帮助我 属性[id]在此收集实例上不存在。


我的admin_table.刀片


@foreach ($users as $positions)

    @foreach ($positions->admins as $position )

        <tbody>

        <tr>

            <td>{{ $position->id}}</td>

            <td>{{ $position->first_name}}</td>

            <td>{{ $position->last_name}}</td>

            <td>{{ $position->contact}}</td>

            <td>{{ $position->departments->department}}</td>

            <td>{{ $position->schoolpositions->school_position}}</td>

            <td>{{ $position->email}}</td>

            <th> <a href="{{action('DashboardController@edit',$position['id' =>$position->id])}} " class="btn btn-success">Edit </a>

            </th>

        </tr>

        </tbody>

    @endforeach


    </tr>

    </tbody>

@endforeach

@endforeach

</table>

这是我的路线


Route::get('/admin_table', 'DashboardController@index');

Route::put('/admin_table/{id}', 'DashboardController@store');

Route::get('/admin_table', 'DashboardController@show');

Route::get('/teacher_editform/{id}', 'DashboardController@edit');

Route::put('/teacher_editform/{id}', 'DashboardController@update')->name('teacheradminpage.teacher_tableform.teacher_editform');

这是我的控制器


public function edit($id)

{

    $departments =  Department::find($id);

    $users =  Schoolposition::find($id);

    $students =  Student::find($id);

    $admins =  Admin::find($id);

    return view('teacheradminpage.teacher_tableform.teacher_editform', compact('departments','users','students','admins', 'id', 'id', 'id', 'id'));

}


缥缈止盈
浏览 100回答 3
3回答

阿晨1998

此代码中有几个可能需要注意的问题。该错误的主要问题似乎是您有一个循环路径可以在循环内的选项卡中获取该路径。position$positionanchor此部分可能不会创建您想要的内容:@foreach&nbsp;($users&nbsp;as&nbsp;$positions) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@foreach&nbsp;($positions->admins&nbsp;as&nbsp;$position&nbsp;)这大致是说 - 以我的用户集合为例,制作一个直接附加到每个对象的位置的新集合。从这里,获取该集合并尝试查找附加到该集合的管理员集合,然后找到 .(我认为这与它试图做的事情很接近...)userpositions$position当你到达循环的内部和你的 / 时,你要求找到一个可能不存在的东西,或者再次找到一个集合。anchorrouteanchorid您已经进入了此视图。将其用作顶级循环项是有意义的,不是吗?admins要修复,请使用作为唯一的循环项:admins&nbsp;@foreach&nbsp;($admins&nbsp;as&nbsp;$position&nbsp;)

素胚勾勒不出你

您的问题是您在数组之前放置了一个额外的。您的路线应该是$position<a&nbsp;href="{{action('DashboardController@edit',['id'&nbsp;=>$position->id])}}&nbsp;"&nbsp;class="btn&nbsp;btn-success">Edit&nbsp;</a>

阿波罗的战车

编辑边栏选项卡@foreach ($users as $positions)@if(!empty($positions->admins)@foreach ($positions->admins as $position )&nbsp; &nbsp; <tbody>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->id}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->first_name}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->last_name}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->contact}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->departments->department}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->schoolpositions->school_position}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <td>{{ $position->email}}</td>&nbsp; &nbsp; &nbsp; &nbsp; <th> <a href="{{action('DashboardController@edit',$position['id' =>$position->id])}} " class="btn btn-success">Edit </a>&nbsp; &nbsp; &nbsp; &nbsp; </th>&nbsp; &nbsp; </tr></tbody>@endforeach</tr></tbody>@endforeach@endif@endforeach&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</table>
打开App,查看更多内容
随时随地看视频慕课网APP