Code Monkey home page Code Monkey logo

laravel-multisite's Introduction

Laravel Multisite

Latest Version on Packagist Total Downloads Software License Build Status

With this package it is possible to build multiple sites/(sub)domains on one codebase.

Installation

You can install the package via composer:

composer require appstract/laravel-multisite

Config (hosts, homestead)

You need to add the sites to your /etc/hosts file and Homestead.yaml. For example, mywebsite.dev and blog.mywebsite.dev. In the Homestead.yaml, you need to map the sites to the same folder.

Publish

By running php artisan vendor:publish --provider="Appstract\Multisite\MultisiteServiceProvider" in your project all files for multisite will be published. The files that will be published are: a migration, a seeder and a config file.

Seeder

The seeder will be published but needs to be run when running php artisan db:seed, so you need the add $this->call(SitesTableSeeder::class); to your DatabaseSeeder.php file. After migrating and seeding the sites are now present in the database.

Usage

This is the main part, within your routes/web.php you can set routes for your sites within route groups, like this:

Route::group([
    'domain' => 'blog.'.config('multisite.host'),
    'as' => 'blog.',
    'middleware' => 'site:blog'
], function () {
    Route::get('/', 'BlogController@homepage')->name('homepage');
});

The magic happens with the site middleware site:blog. This will tell your app that the routes within the group are belonging to the blog. It will provide a variable called $currentSite in all your views. There is also a config available, which you can access with Config::get('multisite.site').

Testing

$ composer test

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

laravel-multisite's People

Contributors

303k avatar gizburdt avatar ovanschie avatar svenluijten avatar zssarkany 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

laravel-multisite's Issues

Routes

Hi

How are routes handled for adding to blade files? When I call a route I'm getting the URL for the site in my normal config rather than the site that returns from the current_site() function.

Should I be calling routes in a different manner?

Thanks!

current_site returns null in controller contructor

Hi

I have an issue ithat within my controller __construct method the current_site function returns null i.e the multi_site object hasn't yet been setup.

public function __construct()
{

//this returns null
var_dump(current_Site());

}

public function index()
{
//this works
var_dump(current_Site());

}

Is there a way to have the current site helper function available in the contructor?

Thanks

Example ?

Hi,
do you have the example of using this package ?

Homestead

Hi,

Do I need to install the vagrant box & homestead for using this plugin. If yes what is the sequence of installation & the folder structure?

  1. Laravel
  2. Vagrant Box
  3. Homestead
    What is the folder structure.

Sorry if it is a very basic question but as I am very new to all this I am unable to make out what is going wrong.

Laravel 5.3 missing aliasMiddleware

aliasMiddleware doesn't exists.

image

It can be fixed by adding this to MultisiteServiceProvider:

   // Middleware
        if (method_exists($router, 'aliasMiddleware')) {
            $router->aliasMiddleware('site', CurrentSite::class);
        } else {
            $router->middleware('site', CurrentSite::class);
        }

domain setup

Hi

I'm having trouble with the last few steps in the setup guide.

Can you give we a real world example of what data I put in the sites database table?

currently i have.

name = test1
slug = test1.homestead.app
route is blank?
url = test1

I don't understand what I need to put put into routes/web.php ?
I dont have the $currentSite var availble

Could you give me some examples and guidence please?

ta

Nothing to publish for tag [].

Hi,

I tried your package with Laravel Framework version 5.2.45 and Homestead, but when I run command:

artisan vendor:publish --provider="Appstract\Multisite\MultisiteServiceProvider"

It return 'nothing to publish for tag[]'.

Is this working with Laravel 5.4?

Hi. Is this package working with L 5.4? Cause when I type

php artisan vendor:publish --provider="Appstract\Multisite\MultisiteServiceProvider"

nothing is publishing :/

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.