How can I define a route that doesn't redirect to team missing page
When I define the user CanJoinTeams the middleware VerifyUsersHasTeam redirect the user to a team\missing, because I don't have a team setup. I want to find a way to bypass the team verification for the admin. Is that possible?
Yeah! So in your middleware you can do something like this
public function handle($request, Closure $next, $guard = null)
{
if ($this->isAdmin()) {
return $next($request); // By pass the middleware
}
if ($this->canJoinTeams()) {
// Redirect to "team missing"
}
return $next($request);
}
@bobbybouwmann thank you, I did as you suggested, but it keeps happening on redirect me to team/missing. So I noticed that the route was with middleware set by default.
The route web have been set by default the middleware hasTeam, with that in mind I can made my own route admin. Laravel Spark changes the default web route and add a middleware hasTeam. Check the RouteServiceProvider file in app/Providers/RouteServiceProvider.php
protected function mapWebRoutes(Router $router)
{
$router->middleware(['web', 'hasTeam'])
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
Mmh I could have told you that as well ;) Only I didn't know how you were using your middleware. Global or per group or per route. Anyway, glad you solved your problem ;)
I have a custom landing page for welcome.blade.php, and then I configured the Spark logo in the dashboard to go back to welcome.blade.php instead of going to /home.
But I found out if the user does not have a team, he is constantly redirected to /home and unable to get to welcome.blade.php because of the middleware.
Here is what I did to allow him to go back to welcome.blade.php without being redirected:
/spark/src/Http/Middleware/VerifyUserHasTeam.php
namespace Laravel\Spark\Http\Middleware;
use Laravel\Spark\Spark;
class VerifyUserHasTeam
{
/**
* Verify the incoming request's user belongs to team.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, $next)
{
if ($request->url() === "/" || $request->url() === "https://captifi.net" || $request->url() === "https://captifi.net/" || $request->url() === "http://captifi.net" || $request->url() === "http://captifi.net/") {
return $next($request);
}
if (Spark::usesTeams() && $request->user() && ! $request->user()->hasTeams()) {
return redirect(Spark::teamsPrefix().'/missing');
}
return $next($request);
}
}