Code Monkey home page Code Monkey logo

awesome-landlord's Introduction

awesome-landlord's People

Contributors

bissolli avatar christian-thomas avatar divdax avatar geomagilles avatar grahamcampbell avatar jbrooksuk avatar luizreginaldo avatar mbardelmeijer avatar nunomazer avatar omranic avatar phaberest avatar renanwilliam avatar rikvdlooi avatar tonydew avatar torkiljohnsen avatar vernesto84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

awesome-landlord's Issues

Call to a member function newQueryWithoutTenants() on null

I'm in the middle of upgrading PHP to 7.3.9, Laravel to 5.6, and my app so I am migrating to your fork (which thank you by the way). But part of my code is trying to do a query without the tenants and it's failing.

// in DataProvider class
    protected function getPhotoQuery()
    {
        return Photo::allTenants() // <---- error here
            ->select('photos.*')
            ->join('photo_player', 'photos.id', '=', 'photo_player.photo_id')
            ->where('photo_player.season_id', '=', $this->playerSeason->season_id)
            ->where('photo_player.player_id', '=', $this->player->id)
            ->orderBy('photos.created_at', 'desc');
    }
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Call to a member function newQueryWithoutTenants() on null"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalThrowableError in PATH\vendor\torzer\awesome-landlord\src\BelongsToTenants.php:69

Here's the entirety of my Photo class

<?php

namespace App\Models;

use Torzer\Awesome\Landlord\BelongsToTenants AS BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class Photo extends Model
{
    use BelongsToTenant;

    public function getPhotoAttribute()
    {
        return config('urls.photos') . '/' . $this->file . '.jpg';
    }

    public function getThumbAttribute()
    {
        return config('urls.photos') . '/thumbs/' . $this->file . '.jpg';
    }

    public function getJSONData(Player $player = null)
    {
        $json = ['main'=>null, 'also'=>[]];
        $playersTemp = $this->players;

        if($player != null){
            $playersTemp = $playersTemp->reject(function($p) use($player) {
                return $p->id === $player->id;
            });

            $json['main'] = $player->toArray();
        }

        if($playersTemp->count()){
            $json['also'] = $playersTemp->toArray();
        }

        return json_encode($json);
    }

    public function albums()
    {
        return $this->belongsToMany('App\Models\PhotoAlbum', 'album_photo');
    }

    public function players()
    {
        return $this->belongsToMany('App\Models\Player');
    }
}

Tenant Breaks With ModelObserver

I have a mobel that uses tenancy and a model observer, but the second I try to add the observer the query stops adding the tenant conditions. I even have it to where the observer class has no actual code to run, so it appears to be just the act of adding it breaks.

// app.php#providers
// lots of others not shown, but order persists
Torzer\Awesome\Landlord\LandlordServiceProvider::class,
App\Providers\AppServiceProvider::class,
App\Providers\TenantServiceProvider::class,
// AppServiceProvider#boot 
Game::Observe(PersistToObserver::class);
// TenantServiceProvider#boot
// lots of other things that are confirmed working properly
Landlord::addTenant('site_id', $site->id);
Landlord::addTenant('season_id', $season->id);
// PersistToObserver
class PersistToObserver {
     // everything is commented out
}
// Game Model
class Game extends Model implements Shareable, IPersistTo
{

    use BelongsToTenants, Event, UsesCustomCollection;

    // other model stuff
}
// Route controller query in question
$results = Game::with('location')
            ->withCount(['album', 'stats', 'updates'])
            ->results()
            ->take(4)
            ->get();

I've stripped that query down to nothing but Game::get() and it still doesn't apply. All of those withCount models have the same tenancy and the sub query for those work all the time. Its only when that Game is observed. Comment out that line in AppService#boot and tenancy works again.

On Laravel 5.6.39 and 3.1.0 of this pacakge

Unable to get Landlord tenant to work.

Hi,

I have followed your instructions but this package isnt injecting the where "company_id = X" into the SQL queries.

  1. Added the Landlord Service Provider in the config/app.php
  2. Added the alias in the config/app.php
  3. Created config file and set the tenant_id to company_id
  4. Created and set the landlord middleware and I know that works
  5. Added BelongsToTenants scope to the user model

When all call $usersList = User::all('name', 'email','phone_number','profile_url'); in the userController, the company_id is not injected in the sql. I even had \Landlord::enable() called before that to make sure it is on.

What do you think I could be doing wrong?

Thanks

Tenant is adding on midlleware buts on traist is null

public function handle($request, Closure $next)
    {

        if (auth()->check()) {
            if (auth()->user()->tenant_id) {
                Landlord::addTenant('tenant_id', \auth()->user()->tenant_id);
            }
        }
        dd(Landlord::getTenants());
        return $next($request);
    }

dump:
Illuminate\Support\Collection {#1315 ▼
#items: array:1 [▼
"tenant_id" => 2
]
}

public static function bootBelongsToTenants()
    {

        // Grab our singleton from the container
        static::$landlord = app(TenantManager::class);

        // Add a global scope for each tenant this model should be scoped by.
        static::$landlord->applyTenantScopes(new static());
        dd(static::$landlord);

        // Add tenantColumns automatically when creating models
        static::creating(function (Model $model) {
            static::$landlord->newModel($model);
        });

    }

dump:
Torzer\Awesome\Landlord\TenantManager {#1314 ▼
#enabled: true
#tenants: Illuminate\Support\Collection {#1315 ▼
#items: []
}
#deferredModels: Illuminate\Support\Collection {#1316 ▼
#items: array:1 [▼
0 => Modules\System\Entities\Usergroup {#1317 ▶}
]
}
}

But when I put the content of middleware on applyTenantScopes function it works and my request is filtered by tenant_id perfectly:

public function applyTenantScopes(Model $model)
    {

        if (!$this->enabled) {
            return;
        }

        if (auth()->check()) {
            if (auth()->user()->tenant_id) {
                $this->addTenant(auth()->user()->tenant, \auth()->user()->tenant_id);
            }
        }
....

I wanna understand what I'm doing wrong, please

How do you make multiple tenants or landlord?

Hi! Let say i have users who are linked to a shop. Users can make shops and other data like customers and etc are linked via the shop model.

Do I need to add multiple tenants?
LandLord::addTenant($request->user());
users should still be able to create shops but can only view created shops
LandLord::addTenant($request->shop());

Very old bug with multiple tenant columns on a model

Referencing the conversation in hipsterjazzbo#66, you will note that the end of the chain terminates with renanwilliam having introduced a critical bug and making the excuse that it was okay because the code he wrote passed the test package. Which was true, I confirmed it myself.

However, renanwilliam ignored the fact that it did not pass the "does this do what the docs says it will do" test.

That is probably the most important test for any library.

Help with Laravel 5.7

I'm using next code
Landlord :: addTenant ('schema_id', 3);
$ac = \App\Accounts::all();

Return
{
id: 1
schema_id: 1,
name: 'Demo 1'
},
{
id: 2,
schema_id: 2,
name: 'Demo 2'
}

what am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.