@Cronix Thank you for helping me again. I think my logic is messed up. Here is the workflow: As an admin, I can choose an organization, then go to the organization index page to CRUD the receiver list for the organization.
The first step I did is create a find function in my ReceiverController, which is asking me which organization do you want to see.
public function find()
{
$organizations = Organization::pluck('organization_name', 'id')->except([1]);
return view('receivers.find', compact('organizations'));
}
The second step is going to the index page with my index function, the organization_id will be the one I passed from my first step. The url will be like http://localhost:8888/textapp/public/receivers?organization_id=2
public function index(Request $request)
{
$organization = Organization::findOrFail($request->organization_id);
$receivers = User::where('organization_id', '=', $request->organization_id)->where('role_id', '=', 5)->get();
return view('receivers.index', compact('receivers', 'organization'));
}
The third step is add a receiver, then add a new receiver, after save the receiver, I used the store function for that.
public function store(Request $request)
{
$user = User::create($request->all());
$user->save();
$organization = Organization::findOrFail($request->organization_id);
$receivers = User::where('organization_id', '=', $organization->id)->where('role_id', '=', 5)->get();
// return redirect()
// ->route('receivers.index', compact('organization', 'receivers'))
// ->with('success', $user->phone_number . ' created successfully.');
return view('receivers.index', compact('organization', 'receivers'))->with('success', $user->phone_number . ' created successfully.');
}
But it is not returning me to the index page with my message showing up.