archtechx / tenancy Goto Github PK
View Code? Open in Web Editor NEWAutomatic multi-tenancy for Laravel. No code changes needed.
Home Page: https://tenancyforlaravel.com
License: MIT License
Automatic multi-tenancy for Laravel. No code changes needed.
Home Page: https://tenancyforlaravel.com
License: MIT License
Perhaps some of these?
>>> tenancy()->put('foo', [1, 2]);
=> [
1,
2,
]
>>> tenancy()->get('foo')
=> "Array"
Arrays should be serialized into JSON, but then JSON strings need to be recognized from regular strings.
This will improve performance.
5.7 tests are passing but 5.8 aren't. Seems to be a change in Artisan syntax? https://travis-ci.com/stancl/tenancy/jobs/194956720
Also neither version's tests should be passing due to #38
Code like this is problematic:
public static function productImage($product_id)
{
return asset("storage/images/products/$product_id.png");
}
\Image::make($image)
->resize(750, 750, $constraint)//->resizeCanvas(750, 750)
->save(storage_path("app/public/images/products/{$product->id}.png"))
->resize(300, 300, $constraint)//->resizeCanvas(300, 300)
->save(storage_path("app/public/images/products/thumbnails/{$product->id}.png"));
But code like this seems to work (= doesn't delete the image, since the code above put it in the wrong directory):
if (\Helper::imageExists($product->id) && $image_deleted) {
Storage::delete("public/images/products/{$product->id}.png");
Storage::delete("public/images/products/thumbnails/{$product->id}.png");
}
storage_path()
and asset()
app()->useStoragePath(app()->storagePath() . $path)
app('url')->forceRootUrl(asset('') . $url)
Events
Jobs
Events happen only in the lifecycle of a request, so assuming the tenant is identified at the beginning and then not switched, events are ok. (Support for events even with reidentification should be added at some point).
I was trying to test this package in a brand new Laravel 5.8 app, I went as far as
https://github.com/stancl/tenancy#creating-a-new-tenant
and in the next step, I got the error of
Symfony\Component\Debug\Exception\FatalThrowableError : Undefined class constant 'OPT_PREFIX'
on
/vendor/stancl/tenancy/src/StorageDrivers/RedisStorageDriver.php:75
Thanks
Why are files in {storage_path()}/app/public
in the image in README?
https://github.com/stancl/tenancy/blob/1.x/src/TenantManager.php#L200
Says array
but it's a collection.
This should increase performance.
Some people prefer facades over global helpers and creating one shouldn't be too hard.
>>> cache()->tags([1,2])->getTags()->getNames()
=> [
1,
2,
]
>>> tenancy()->init()
=> [
"uuid" => "[...]",
"domain" => "laravel.localhost",
"foo" => [
"a" => "b",
"c" => "d",
],
]
>>> cache()->tags([1,2])->getTags()->getNames()
=> [
"tenant45b1a950-2d81-11e9-a4f5-bf999e894159",
[
1,
2,
],
]
It would be run before phpunit.
Closed: Maybe this will be useful later. For now, this is not a priority.
I am getting error while while creating tenent in tinker
>>> tenant()->create('tenant1.localhost')
=> [
"uuid" => "e5611150-9a9e-11e9-8315-b9eb127de2b8",
"domain" => "tenant1.localhost",
]
Error
PHP Parse error: Syntax error, unexpected T_DOUBLE_ARROW on line 1
I tried on different projects , different php versions bu no luck.
I was following this article
https://stancl.github.io/blog/how-to-make-any-laravel-app-multi-tenant-in-5-minutes/
Thanks for this incredible package.
@stancl
I stumbled upon your blog post, I will say i am really impressed by your package, I would say it remove 99% time meant for the development of multi-tenancy app.
But i hit a snag because i could not get the complete documentation.
I would love it if you could write more tutorials on how to build a panel/control dashboard to create, delete and suspend a tenant app.
Preferably continuing from your Tutorial.
I have an app which i am working which allow user's to send emails On the free plan and Limited number of SMS on the pro plan.
Currently i use hard coded variables for that. Something like this in my controller
$use_sms = true; if($use_sms === true){ //Function to send SMS }
How do i do such using your package..
Thanks.
Moneya
Right now it's necessary to test the features in a laravel/laravel instance.
Add laravel/framework and artisan tinker
to require-dev?
>>> tenant()->delete('nonexistent_uuid')
PHP Notice: Undefined index: domain in /.../StorageDrivers/RedisStorageDriver.php on line 58
>>> storage_path()
=> "/var/www/laravel/test/storage"
>>> tenancy()->all()
=> Illuminate\Support\Collection {#3181
all: [
[
"uuid" => "8075a580-1cb8-11e9-8822-49c5d8f8ff23",
"domain" => "dev.localhost",
],
[
"uuid" => "1e22e620-1cb8-11e9-93b6-8d1b78ac0bcd",
"domain" => "laravel.localhost",
"abc" => "def",
],
],
}
>>> tenancy()->init('dev.localhost')
=> [
"uuid" => "8075a580-1cb8-11e9-8822-49c5d8f8ff23",
"domain" => "dev.localhost",
]
>>> storage_path()
=> "/var/www/laravel/test/storage/tenant8075a580-1cb8-11e9-8822-49c5d8f8ff23"
>>> tenancy()->init('laravel.localhost')
=> [
"uuid" => "1e22e620-1cb8-11e9-93b6-8d1b78ac0bcd",
"domain" => "laravel.localhost",
"abc" => "def",
]
>>> storage_path()
=> "/var/www/laravel/test/storage/tenant8075a580-1cb8-11e9-8822-49c5d8f8ff23/tenant1e22e620-1cb8-11e9-93b6-8d1b78ac0bcd"
Check if it breaks anything else (write a test).
__invoke()
able similarly to TenantManagerTODO: Add some method/class that would use the config stored in this variable:
>>> tenant()->put('foo', ['a' => 'b']);
=> {#3209
+"a": "b",
}
>>> tenant()->currentDomain()
=> "laravel.localhost"
Could be due to some weird config on my computer.
Perhaps predis could work if tenancy support for Redis was disabled in the config?
When the yourclient.yourapp.com
, yourclient2.yourapp.com
model is used, a wildcard cert can take care of HTTPS. However, when the yourapp.yourclient.com
, yourapp.yourclient2.com
model is used, there needs to be some feature for HTTPS management. Luckily file-based verification can be used with Let's Encrypt, so perhaps creating a route to verify the domain ownership is sufficient? Auto renewal etc could be added too.
>>> tenancy()->findByDomain('laravel.localhostt')
TypeError: Argument 1 passed to Stancl/Tenancy/TenantManager::find() must be of the type string, null given, called in /var/www/laravel/test/vendor/stancl/tenancy/src/TenantManager.php on line 152
This conversion should be done in the TenantManager, to keep the storage drivers' code as straightforward as possible.
Like Stripe administration.
I'm not sure if there are many practical uses for this, but code-wise this shouldn't be hard to add.
Also add API to easily add and remove domains.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.