imposition

imposition

Member Since 2 Years Ago

GoioerĂȘ

Experience Points
4,690
Total
Experience

310 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
30
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
4,690 XP
Feb
10
3 months ago
Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas for what i could understand reviewing some stuff. i'm just linking fqnd and website uuid with "super admin"... Thank you again for the help. this actually was going to be a problem moving forward.

Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas i'll see about that right now. What you said up there worked for me I'll let this sit by for now and review all the project... I was following some tutorial and they did it like this, i'm learning as i'm moving forward. Or trying to Thanks tho Helped a lot

Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas Creating a user to tenant dashboard and user to master dashboard. tenant dashboard will give you controll of ur tenant's info and stuff, master dashboard will give u controll of another features.

Activity icon

Replied to Redirect To Subdomain After Register

Not working ;v

Activity icon

Replied to Redirect To Subdomain After Register

@sinnbeck This

private function tenantExists($name, $email)
   {
       return Tenant::where('name', $name)->orWhere('email', $email)->exists();
   }

actually work.

Activity icon

Replied to Redirect To Subdomain After Register

@sinnbeck perhaps u missunderstood me Just have the class i'm using inside CreateTenant

<?php

namespace App;

use Hyn\Tenancy\Environment;
use Hyn\Tenancy\Models\Hostname;
use Hyn\Tenancy\Models\Website;
use Illuminate\Support\Facades\Hash;
use Hyn\Tenancy\Contracts\Repositories\HostnameRepository;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;

/**
 * @property Website website
 * @property Hostname hostname
 * @property User admin
 */
class Tenant
{
    public function __construct(Website $website = null, Hostname $hostname = null, User $admin = null)
    {
        $this->website = $website;
        $this->hostname = $hostname;
        $this->admin = $admin;
    }

    public static function delete($name)
    {
        $baseUrl = config('tenancy.hostname.default');
        $name = "{$name}.{$baseUrl}";
        if ($tenant = Hostname::where('fqdn', $name)->firstOrFail()) {
            app(HostnameRepository::class)->delete($tenant, true);
            app(WebsiteRepository::class)->delete($tenant->website, true);
            return "Tenant {$name} successfully deleted.";
        }
    }

    public static function deleteByFqdn($fqdn)
    {
        if ($tenant = Hostname::where('fqdn', $fqdn)->firstOrFail()) {
            app(HostnameRepository::class)->delete($tenant, true);
            app(WebsiteRepository::class)->delete($tenant->website, true);
            return "Tenant {$fqdn} successfully deleted.";
        }
    }

    public static function registerTenant($name, $email, $password): Tenant
    {
        // Convert all to lowercase
        $name = strtolower($name);
        $email = strtolower($email);

        $website = new Website;
        app(WebsiteRepository::class)->create($website);

        // associate the website with a hostname
        $hostname = new Hostname;
        $baseUrl = config('tenancy.hostname.default');
        $hostname->fqdn = "{$name}.{$baseUrl}";
        app(HostnameRepository::class)->attach($hostname, $website);

        // make hostname current
        app(Environment::class)->tenant($hostname->website);

        // Make the registered user the default Admin of the site.
        $admin = static::makeAdmin($name, $email, $password);

        return new Tenant($website, $hostname, $admin);
    }

    private static function makeAdmin($name, $email, $password): User
    {
        $admin = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);
        $admin->guard_name = 'web';
        $admin->assignRole('admin');

        return $admin;
    }

    public static function tenantExists($name)
    {
        $name = $name . '.' . config('tenancy.hostname.default');
        return Hostname::where('fqdn', $name)->exists();
    }
}

This one

Activity icon

Replied to Redirect To Subdomain After Register

@sinnbeck nope, just this one.

<?php

namespace App\Console\Commands;

use App\Notifications\TenantCreated;
use App\Tenant;
use Illuminate\Console\Command;

class CreateTenant extends Command
{
Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas

<?php

namespace App;

use Hyn\Tenancy\Environment;
use Hyn\Tenancy\Models\Hostname;
use Hyn\Tenancy\Models\Website;
use Illuminate\Support\Facades\Hash;
use Hyn\Tenancy\Contracts\Repositories\HostnameRepository;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;

/**
 * @property Website website
 * @property Hostname hostname
 * @property User admin
 */
class Tenant
{
    public function __construct(Website $website = null, Hostname $hostname = null, User $admin = null)
    {
        $this->website = $website;
        $this->hostname = $hostname;
        $this->admin = $admin;
    }

    public static function delete($name)
    {
        $baseUrl = config('tenancy.hostname.default');
        $name = "{$name}.{$baseUrl}";
        if ($tenant = Hostname::where('fqdn', $name)->firstOrFail()) {
            app(HostnameRepository::class)->delete($tenant, true);
            app(WebsiteRepository::class)->delete($tenant->website, true);
            return "Tenant {$name} successfully deleted.";
        }
    }

    public static function deleteByFqdn($fqdn)
    {
        if ($tenant = Hostname::where('fqdn', $fqdn)->firstOrFail()) {
            app(HostnameRepository::class)->delete($tenant, true);
            app(WebsiteRepository::class)->delete($tenant->website, true);
            return "Tenant {$fqdn} successfully deleted.";
        }
    }

    public static function registerTenant($name, $email, $password): Tenant
    {
        // Convert all to lowercase
        $name = strtolower($name);
        $email = strtolower($email);

        $website = new Website;
        app(WebsiteRepository::class)->create($website);

        // associate the website with a hostname
        $hostname = new Hostname;
        $baseUrl = config('tenancy.hostname.default');
        $hostname->fqdn = "{$name}.{$baseUrl}";
        app(HostnameRepository::class)->attach($hostname, $website);

        // make hostname current
        app(Environment::class)->tenant($hostname->website);

        // Make the registered user the default Admin of the site.
        $admin = static::makeAdmin($name, $email, $password);

        return new Tenant($website, $hostname, $admin);
    }

    private static function makeAdmin($name, $email, $password): User
    {
        $admin = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);
        $admin->guard_name = 'web';
        $admin->assignRole('admin');

        return $admin;
    }

    public static function tenantExists($name)
    {
        $name = $name . '.' . config('tenancy.hostname.default');
        return Hostname::where('fqdn', $name)->exists();
    }
}

My Tenant Class... Don't know wtf isn't working cuz inside the command CreateTenant i use the same sentence

return Tenant::where('name', $name)->orWhere('email', $email)->exists();

Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas Call to undefined method App\Tenant::where()

Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas tried that... didn't work. But your answers gave me some clarity...

Activity icon

Replied to Redirect To Subdomain After Register

@sti3bas This way $this->redirectTo = $user->name . '.example.com'; it tries to redirect me to example.com/name.example.com not name.example.com

But i think i can work around that.

Activity icon

Replied to Redirect To Subdomain After Register

But i don't want to redirect away... I want to redirect to it's subdomain. Can you give me an example?

Activity icon

Started a new Conversation Redirect To Subdomain After Register

Hi there, I'm messing around with Multi tenancy but now i don't know how to make my default register form redirect my user to it's subdomain.

Here is my register method:

    protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
        Artisan::call('tenant:create', ['name' => $data['name'], 'email' => $data['email'], 'password' => $data['password']]);
        return $user;
    }

It's calling this command:

 public function handle()
    {
        $name = $this->argument('name');
        $email = $this->argument('email');
        $password = $this->argument('password');

        if (Tenant::tenantExists($name, $email)) {
            $this->error("A tenant with name '{$name}' already exists.");
            return;
        }

        $tenant = Tenant::registerTenant($name, $email, $password);
        $this->info("Tenant '{$name}' is created and is now accessible at {$tenant->hostname->fqdn}");

        // invite admin
        $tenant->admin->notify(new TenantCreated($tenant->hostname));
        $this->info("Admin {$email} can log in using password {$password}");
    }

     private function tenantExists($name, $email)
    {
        return Tenant::where('name', $name)->orWhere('email', $email)->exists();
    }

     private function addAdmin($name, $email, $password)
    {
        $admin = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);
        $admin->guard_name = 'web';
        $admin->assignRole('admin');

        return $admin;
    }

So it can create the appropriate tenant and stuff... After all that's done i want it to redirect to tenant's subdomain... Ex: Acess example.com/register Register and then redirect to tenant.example.com/login or tenant.example.com/dashboard

Don't know how to do that exactly

Jan
30
4 months ago
Activity icon

Replied to Authentication Within Authentication

I googled around and started with multi-tenancy. Having some troubles but getting there.

Jan
28
4 months ago
Activity icon

Replied to Authentication Within Authentication

Something like that

Activity icon

Replied to Authentication Within Authentication

Almost but not quite. I'll try to organize my thoughts better... To see if i can present the idea better.

Activity icon

Started a new Conversation Authentication Within Authentication

Hi there, I was wondering if i can do an authentication within the authentication... For example: I want to register a company and within that company i want to register users... Each company with a dashboard and each user with a dashboard within the company's dashboard.