I have some code I use in some methods inside different controllers.
What is the best way to implement it as a function outside the controllers?
I think the abort(404); might be an issue here...
class UserController extends Controller
{
public function index(Request $request, $id = false)
{
if (empty($id))
{
$id = Auth::user()->id;
}
if (Auth::user()->isSuperUser())
{
$user = User::where('id', $id)
->withTrashed()->first();
if (!$user)
{
abort(404);
}
}
elseif (Auth::user()->id == $id)
{
$user = User::findOrFail($id);
}
else
{
abort(401);
}
}
}