livewire / livewire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
MIT License
22.2k stars 1.54k forks source link

Error on global scope after initial request #2693

Closed joshfom closed 3 years ago

joshfom commented 3 years ago

Description

Hi I am facing issues using global scope everything works well on initial request, I get an error on hydrate (subsequent request) after the component is loaded

I am working on a Multi Tenant CMS, we have everything working with Controllers and Blade, we want to make it more real-time, First we convert to Inertia Js which everything is working perfectly fine no errors, we are short of Vue developer in our team then we decided to shift all to Livewire which is great and all seems well until we started adding forms to create models.

On initial request the scope works with no issue, we get a warning if we use wire:model="" on input as seen below

TypeError
Argument 1 passed to App\Tenant\Scope\TenantScope::__construct() must be an instance of Illuminate\Database\Eloquent\Model, null given, called in D:\laragon\www\vistate\app\Tenant\Traits\ForTenants.php on line 19

Exact steps to reproduce

my scope

<?php

    namespace App\Tenant\Scope;

    use Illuminate\Database\Eloquent\Builder;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\Scope;

    class TenantScope implements Scope
    {
        public $company;

        public function __construct (Model $company)
        {
            $this->company = $company;
        }

        public function apply(Builder $builder, Model $model)
        {
            return $builder->where($this->company->getForeignKey(), '=', $this->company->id);
        }
    }

Everything works well as expected with normal controllers/blade and Laravel/Inertia Js full CRUD operation with the global scope

Please any heads up on how to troubleshoot, maybe it has something to do with hydrate and dehydrate?

Or any recommended Multi-Tenancy package that will work with Livewire

Thanks in Advance

Context

joshfom commented 3 years ago

I got it figured out. I over calculated, tenant hash_id is in the session I could reach out to it no need to pass the whole model

squishythejellyfish commented 3 years ago

👋 Oh Hi! I'm Squishy, the friendly jellyfish that manages Livewire issues.

I see this issue has been closed.

Here in the Livewire repo, we have an "issues can be closed guilt-free and without explanation" policy.

If for ANY reason you think this issue hasn't been resolved, PLEASE feel empowered to re-open it.

Re-opening actually helps us track which issues are a priority.

Reply "REOPEN" to this comment and we'll happily re-open it for you!

(More info on this philosophy here: https://twitter.com/calebporzio/status/1321864801295978497)