Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Middleware for Laravel 5.5 #79

Open
ServerJunge opened this issue Oct 5, 2017 · 2 comments
Open

Example Middleware for Laravel 5.5 #79

ServerJunge opened this issue Oct 5, 2017 · 2 comments

Comments

@ServerJunge
Copy link

Hi guys,

does anyone have an example for a working middleware for Laravel 5.5 where you set the tenant by the users tenant id and with auth:api routes?

Route::middleware('auth:api:web')

@hmamman
Copy link

hmamman commented Apr 25, 2018

<?php

namespace App\Http\Middleware;

use Closure;
use HipsterJazzbo\Landlord\Facades\Landlord;
use Illuminate\Support\Facades\Auth;

class Tenancy
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = Auth::guard()->user();

        Landlord::addTenant('tenant_id', $user->tenant_id);

        return $next($request);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants