Coder Social home page Coder Social logo

ashokgelal / townhouse Goto Github PK

View Code? Open in Web Editor NEW
251.0 28.0 85.0 351 KB

A multi-tenant Laravel app for listing property rentals

Home Page: https://medium.com/@ashokgelal/writing-a-full-featured-multi-tenant-laravel-app-from-scratch-a0e1a7350d9d

PHP 84.34% Vue 0.33% HTML 15.33%
laravel multi-tenancy tutorial multi-tenant php database full-stack complete

townhouse's Introduction

townhouse's People

Contributors

ashokgelal avatar colinmackinlay avatar drbyte avatar fsantana avatar gruz 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

townhouse's Issues

Database [tenant] not configured.

Hi, after create all post How create Milti-tenant all work fine but when reset password show an error
Database [tenant] not configured.
Laravel: 5.5
multi-tenant: 5.0

Getting... "This site can’t be reached"

Hi
I followed all the steps in my system (W10, Apache2 and MySQL) but when I try to open boise.townhouse.dev in browser then its not showing any page for me and its redirecting to https also.

Do I need to add vhost in apache to make it work?

Thanks,
Anil

Middleware only in subdomain

Hi,
I have a question, in the middleware enforce.tenancy is by default for all tenants, but
I would like that only was for the subdomain url subdomain.domain.com,
for the domain.com middleware It should be web.

How I can change in the EnforceTenancy middleware?

Thanks!!

MariaDB --error on command CreateTenant

Hi I have an error when I create a tenant from console:

#php artisan tenant:create boise [email protected]

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS 51d58fb26e6a436b83e835a3cbbb432b@'127.0.0.1' IDENTIFIED BY '1ce8' at line 1 (SQL: CREATE USER IF NOT EXISTS 51d58fb26e6a436b83e835a3cbbb432b@'127.0.0.1' IDENTIFIED BY '1ce8cd62c029a370c4b063151678c542')

at /home/user/Apps/workshop_proj/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {

664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|

Exception trace:

1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS 51d58fb26e6a436b83e835a3cbbb432b@'127.0.0.1' IDENTIFIED BY '1ce8' at line 1")
/home/user/Apps/workshop_proj/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:82

2 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS 51d58fb26e6a436b83e835a3cbbb432b@'127.0.0.1' IDENTIFIED BY '1ce8' at line 1")
/home/user/Apps/workshop_proj/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:80

Please use the argument -v to see more details.

The given data was invalid

In the refactoring I found an error The given data was invalid. and to solve it I had to change the way in which the relations of the hostname and the website are made.

the relationship to website

$website->customer_id = $customer->id;
$hostname->customer_id = $customer->id;
$hostname->website_id  = $website->id;

the relationship to hostname

$hostname->customer_id = $customer->id;
$hostname->website_id  = $website->id;

and now it works!!

;)

create tenant error

When i try to create tenant getting error

tenancy>php artisan tenant:create boise [email protected]

Symfony\Component\Debug\Exception\FatalThrowableError : Class 'Hyn\Tenancy\Models\Customer' not found

at tenancy\app\Console\Commands\CreateTenant.php:46
42| }
43|
44| private function tenantExists($name, $email)
45| {

46| return Customer::where('name', $name)->orWhere('email', $email)->exists();
47| }
48|
49| private function registerTenant($name, $email)
50| {

Exception trace:

1 App\Console\Commands\CreateTenant::tenantExists("boise", "[email protected]")
tenancy\app\Console\Commands\CreateTenant.php:27

2 App\Console\Commands\CreateTenant::handle()
tenancy\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29

Please use the argument -v to see more details.

New realease of tenancy (5.2 - no longer Customer model)

Hi Ashok,

I have started a new project based on your tutorial (Great by the way...bravo), but noticed that recently 5.2 of tenancy package was released and they did a big change in the package.
The Customer model no longer present.
Will you update the tutorial? Can you give some hints on this?

Big thanks to you.

i have error create apache conf in ubunu

hi , thank you for this nice project..
after install in in command php artisan tenant:create bosto 123456 [email protected] and set webserver.php > apache = true it cant run apache2ctl graceful it need sudo aslo i set sudo apache2ctl graceful in webserver.php get password but have other errors ...
please help me how i can run this project in user non sudo

Error while creating tenant

When I try to create admin user for tenant I get the below error:

Method Illuminate\Database\Query\Builder::assignRole does not exist.

Submit reset password form refreshes page

Hello

I have implemented your multi-tenant approach and reskinned the password reset page to fit with my application.

When I click the link in the email it loads the page fine, I populate the details and submit but it refreshes the page rather than progressing to the /home route. I thought originally that the password reset was submitted just didnt route to my dashboard (home) page, however when I try to login via the regular auth/login form I get "These credentials do not match our records." prompt.

I've double and tripple checked the default reset page blade code against my modified code and i'm not missing anything relating to the form.

Any ideas?

My reset.blade.php code...

`

<form method="POST" action="{{ route('password.request') }}">
  @csrf
  <input type="hidden" name="token" value="{{ $token }}">
  <div class="login-wrapper wd-300 wd-xs-350 pd-25 pd-xs-40 bg-white rounded shadow-base">
    <div class="signin-logo tx-center tx-28 tx-bold tx-inverse">
      <span class="tx-normal">TITAN</span>
    </div>
    <div class="tx-center">Welcome to the Titan framework.</div>
    <div class="tx-center mg-b-30">Please set a new password to continue.</div>

    <div class="form-group">
      <input id="email" placeholder="Enter your email address" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
        name="email" value="{{ $email or old('email') }}" required autofocus> @if ($errors->has('email'))
      <span class="invalid-feedback">
        <strong>{{ $errors->first('email') }}</strong>
      </span>
      @endif
    </div>
    <!-- form-group -->
    <div class="form-group">
      <input id="password" placeholder="Choose password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}"
        name="password" required> @if ($errors->has('password'))
      <span class="invalid-feedback">
        <strong>{{ $errors->first('password') }}</strong>
      </span>
      @endif
    </div>
    <!-- form-group -->
    <div class="form-group">
      <input id="password-confirm" placeholder="Confirm password" type="password" class="form-control{{ $errors->has('password_confirmation') ? ' is-invalid' : '' }}"
        name="password_confirmation" required> @if ($errors->has('password_confirmation'))
      <span class="invalid-feedback">
        <strong>{{ $errors->first('password_confirmation') }}</strong>
      </span>
      @endif
    </div>
    <!-- form-group -->
    <button type="submit" class="btn btn-info btn-block">{{ __('Reset Password') }}</button>

  </div>
  <!-- login-wrapper -->
<script src="{{ asset ('/lib/jquery/jquery.js') }}"></script> <script src="{{ asset ('/lib/popper.js/popper.js') }}"></script> <script src="{{ asset ('/lib/bootstrap/bootstrap.js') }}"></script> `

assets not loading

hi,

cloned the project and now when i run it on townhouse.test.

app.js and app.css are not found it result to 404 error.

The response is not a view - ProfileTest.php

I tried replicating step 5 of the tutorial but I'm stuck at ProfileTest.

I'm getting the following when I try to test ProfileTest::edit_renders_correct_view

Code:

/** @test */
public function edit_renders_correct_view()
{
    $user = $this->createUserInTenant();
    $this->signIn($user);
    $response = $this->get(route('tenant.account.profile.edit'));
    $response->assertViewIs('tenant.account.profile');
}

Console:

1) Tests\Feature\ProfileTest::edit_renders_correct_view
The response is not a view.

/home/vagrant/code/townhouse-testing/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:787
/home/vagrant/code/townhouse-testing/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:712
/home/vagrant/code/townhouse-testing/tests/Feature/ProfileTest.php:18

On debugging, I found that $response has a statusCode of 404, where the expected is 200.

I have this repository using commit da862a5 (before 5.2 update) together with my project in Laravel/Homestead and this repository's ProfileTest passes while the ProfileTest for my project fails. I used kdiff3 to compare my project repository with the mentioned commit of this repository and to best of my knowledge all routing related code/configuration is the same.

When I manually create a tenant using sudo php artisan tenant:create boston [email protected], map, I can access the profile page.

Question about custom domain tenants

Hi!

Lets suppose that i have an app called: townhouse.co, and my app can handle multiple services, eg:

creator.townhouse.co
elections.townhouse.co
(each one has its own logic)

then, i need to whitelabel these services (to each town), eg:

creator.london.uk
elections.london.uk

creator.florida.us
elections.florida.us

how i can accomplish that? (note that in the url, we dont use "townhouse.co" anymore, but the city name)

  • I need each city to have its own database (thats ok because each city is a tenant of townhouse) so no worries.
  • I need a custom domain for each city, but mantaining the townhouse subdomais such as "creator." and "elections."

The user and resetPassword migrations are not migrated

Hi, I have a problem with the migrations, when run php artisan tenancy:install run customer, websites, and hostname are migrated, but the user and passwordResets are not migrated because they are into tenant folder when run php artisan migrate

Thanks

Can't access main domain or any of the sub domains on Ubuntu.

I'm on Ubuntu and I have followed of the steps through Part 1. But when I run my server using **php artisan serve ** I get this error message:

Sorry, the page you are looking for could not be found.

Is there a way I can get this working on ubuntu or do I need to get a Macbook?

Failed asserting that exception of type "Illuminate\Database\QueryException" is thrown.

All work fine, but in this line I have commented this line.

/** @test */
    public function tenant_database_is_removed()
    {
        $this->artisan('tenant:create', ['name' => 'xxx', 'email' => '[email protected]']);
        $this->artisan('tenant:delete', ['name' => 'xxx']);
        **//$this->expectException(QueryException::class);**
        $this->assertDatabaseHas('users', ['email' => '[email protected]']);
    }ting that exception of type "Illuminate\Database\QueryException" is thrown.
ispges ➤ t --stop-on-failure                                                                                                                                                                                 git:develop*
PHPUnit 6.5.6 by Sebastian Bergmann and contributors.

...........F

Time: 4.28 seconds, Memory: 22.00MB

There was 1 failure:

1) Tests\Feature\TenantDeleteCommandTest::tenant_database_is_removed
Failed asserting that exception of type "Illuminate\Database\QueryException" is thrown.

FAILURES!
Tests: 12, Assertions: 17, Failures: 1.

How to make it support external websites/domains

Thank you for the great work with this townhouse project!

I want to ask a question that is fundamental to Laravel Tenancy, so that I can know what to expect of townhouse. My question is:

Does Laravel Tenancy (and by extension, townhouse) provide support for external websites/domains?

For example, if I host this Laravel Tenancy app on www.my-saas-domain.com and I have 3 clients from different countries that want my service hosted at www.my-saas-domain.com to be available on their already existing websites, and their websites are www.flamingo.com, www.cupcakes.com, and the third client has his website at www.client3.com:

  1. Is this the whole point to Laravel Tenancy/townhouse and can it be handled like such?
  2. OR must I host them on my site and thus simply give them admin logins and all?
  3. OR is this what services like Cleaver provides and must I use such a service to achieve the above?

Thanks

Cannot access the main domain

Hi there,

Very good tutorial, but still having a problem in accessing the main domain.

I'm able to access the tenants websites, but the main domain not.

any advice on this would be greatly appreciated.

Thank you

There are no commands defined in 'tenant' namespace

I successfully installed tenancy using php artisan tenancy:install

The class CreateTenant is also created at app\Console\Commands\CreateTenant.php

I also added these in providers in app.php
// Hyn multi tenancy.
Hyn\Tenancy\Providers\Tenants\ConfigurationProvider::class,
Hyn\Tenancy\Providers\TenancyProvider::class,
// Hyn multi tenancy webserver integration.
Hyn\Tenancy\Providers\WebserverProvider::class,

and added this in Kernel.php,

protected $commands = [
// Commands\CreateTenant::class
'App\Console\Commands\CreateTenant'
];

But when I run php artisan tenant:create gc [email protected] , I get error "There are no commands defined in "tenant" namespace.

I have cleared config cache many times, but still same error. Please guide what am I missing here.

Thanks

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.