hipsterjazzbo / laravel-multi-tenant

This package has moved to https://github.com/HipsterJazzbo/Landlord
MIT License
144 stars 36 forks source link

'Trying to get property of non-object' when using php artisan db:seed #4

Closed kyranb closed 10 years ago

kyranb commented 10 years ago

Hi there, first of all, huge thanks for putting together this package!

One inconvenience is I have come across is that it breaks my seed files. (Everything else works a charm!)

In particular,when using: ModelName::create and php artisan db:seed --class"ModelName" I receive the error: [ErrorException] Trying to get property of non-object

Do you have any ideas on how to bypass the tenant scope whilst seeding a database?

Cheers

hipsterjazzbo commented 10 years ago

Can you try it with the branch at #3 and let me know if it's still broken?

hipsterjazzbo commented 10 years ago

@kyranb Actually, I've just merged #3 so just do a composer update, check out the [updated reahttps://github.com/AuraEQ/laravel-multi-tenant/blob/master/README.mdME.md), and let me know if it's still an issue.

kyranb commented 10 years ago

@HipsterJazzbo

Thanks! That solution looks pretty good and I can now seed the database without a problem now! (Also handy for when an admin user wants to be able to modify a certain tenants' record through a cms)

Only problem is that now when calling: TenantScope::setTenantId($tenantId) I receive:

Class 'TenantScope' not found

Please forgive my ignorance as I'm new to Laravel. Should I be using use AuraIsHere\LaravelMultiTenant\ScopedByTenant; on my Sessions/Login Controller? Or just on the models were I want to scope the data?

Thanks again!

hipsterjazzbo commented 10 years ago

You can do

use AuraIsHere\LaravelMultiTenant\TenantScope;

in your login controller. I'll probably add a facade in the next few days to make that easier, but for now that should work.

I'll close this issue now, and you can create a new issue if anything else is broken :)