Level 67
public function index() {
$mobs = \App\Mobs::where('team_id', Auth::user()->currentTeam->id)->get();
return view('mobs.index', compact('mobs'));
}
Access the team id the same way you did when storing the Mob
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I am in the process of implementing teams to my Spark project. I have been able to capture the current team id in my create method bellow. Now I would like to only show the current teams data on the index method rather than by user id as I have in the current where statement on the index method.
Can anyone please help?
My controller
public function index() {
$mobs = \App\Mobs::where('team_id','=', Auth::id())->get();
return view('mobs.index', compact('mobs'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('mobs.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate(request(),[
'mob' => 'required' ,
'number' => 'required' ,
]);
\App\Mobs::create([
'mob' => request('mob'),
'number' => request('number'),
'team_id' => $request->user()->currentTeam->id
]);
return redirect('/mobs');
}
public function index() {
$mobs = \App\Mobs::where('team_id', Auth::user()->currentTeam->id)->get();
return view('mobs.index', compact('mobs'));
}
Access the team id the same way you did when storing the Mob
Please or to participate in this conversation.