大兴企业网站建设公司百度搜索引擎平台
我在尝试将表加载到我的create()函数时遇到此错误,以便用户可以从创建用户页面中的team_names列表中进行选择:Call to a member function with() on array
这是我的UserController.php
use Illuminate\Http\Request;
use App\Game;
use App\User;
use App\Team;
...
public function create()
{
$pagetitle = 'Create User';
$teams = Team::orderBy('team_name', 'asc')->get();
if(auth()->user()->user_type !== 'admin'){
return redirect('/')->with('error', "You do not have access to the game you attempted to view.");
}
return view('pages.admin.users.create', compact('pagetitle')->with('teams', $teams));
}
这是我的create.blade.php
@if(count($teams) > 0)
@foreach($teams as $team)
{{$team->team_name}}
@endforeach
@else
No teams found...
@endif
在这种情况下,关系确实无关紧要,尽管我确实已经正确设置了它们。
对于上下文:我正在创建一个“用户”,但加载所有“团队”名称。
任何帮助是极大的赞赏。