Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/appstract/laravel-multisite
Multiple sites on one codebase
https://github.com/appstract/laravel-multisite
laravel middleware multisite package
Last synced: 5 days ago
JSON representation
Multiple sites on one codebase
- Host: GitHub
- URL: https://github.com/appstract/laravel-multisite
- Owner: appstract
- License: mit
- Created: 2017-02-24T11:56:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-23T09:24:36.000Z (over 5 years ago)
- Last Synced: 2024-12-22T03:07:52.576Z (12 days ago)
- Topics: laravel, middleware, multisite, package
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 216
- Watchers: 17
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Multisite
[![Latest Version on Packagist](https://img.shields.io/packagist/v/appstract/laravel-multisite.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-multisite)
[![Total Downloads](https://img.shields.io/packagist/dt/appstract/laravel-multisite.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-multisite)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/appstract/laravel-multisite/master.svg?style=flat-square)](https://travis-ci.org/appstract/laravel-multisite)With this package it is possible to build multiple sites/(sub)domains on one codebase.
## Installation
You can install the package via composer:
```bash
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:
```php
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
``` bash
$ composer test
```## Contributing
Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-multisite/graphs/contributors) :)
## About Appstract
Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on [Medium](https://medium.com/appstract). You can [follow us on Twitter](https://twitter.com/teamappstract), [buy us a beer](https://www.paypal.me/teamappstract/10) or [support us on Patreon](https://www.patreon.com/appstract).
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.