Run two websites with one laravel installation - laravel

How we can use multiple applications with one Laravel installation.
For example:
www.apple.com
www.orange.com
both website will use ONE CORE laravel installation with separate database and all other separate stuff.
Is that possible?
If yes then how?
Also I have done the same thing for CodeIgniter but not sure how i can do with
laravel.

You can use route group for this, it's something like this:
Route::group(['domain' => 'myapp.com'], function () {
Route::get('user/{id}', 'Controller#Method');
});
Official documentation: Sub-domain routing

You can use this package https://github.com/nWidart/laravel-modules to better organize your code into it's separate websites within the same laravel base code. E.g. you can have Website1 and Website2 modules that has their own Controllers, Models, Views, database migrations, etc.

Related

codeigniter 4 enable users to define their own routes

I've started with Codeigniter 4 today. I have an app that I've built with Codeigniter 3 and now I want to upgrade it to CI4. The first thing is to upgrade routes. I have a simple but GREAT solution by enabling users to define their own routes with a simple page, like this:
And it was super easy, just needed to load and update Routes.php file - arrays of routes.
Now, as I am looking at app/config/Routes.php in CI4 I see it is not a simple array but there is much more to it. So, my question is what would be the simplest way to enable users to define their own routes with a webpage?

Laravel routing pattern similar to Yii

I am new to Laravel and by reading a bit its documentation, it seems that for each new page or url I need to define a route in the web.php file. Please correct me if I am wrong.
So, my question is... Is there a way to create a pattern as in YII framework or .NET framework to manage all routes (or most of them) at once by using something like:
{controller}/{action}/{id}
Well not exactly like Yii or .net but you can declare multiple routes in one line using Resource Controllers.
Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code. For example, you may wish to create a controller that handles all HTTP requests for "photos" stored by your application.
You can do so by Route::resource('photos', 'PhotoController');
Read more here

URL Routing: Laravel

I have been working on laravel and have been doing some routing. I was just wondering on what is the difference between writing the route as:
route::get('roles/{id}/edit',rolesController#edit);
versus
route::get('roles/edit/{id}',rolesController#edit);
One difference is clearly visible and that is the placement of the id variable. Can't figure out any other reason. Please provide an explanation on this.
Other than the actual look of the URL, there's no real difference as far as the framework is concerned.
I suppose it's the matter of preference when using any of this. Maybe, for example, if you are giving options of editing the user profile and posts, this might come handy as both are different routes, technically
No difference. It depends on you how you would like to build your routes. But try to user best practices which laravel creator recommend (https://laravel.com/docs/5.7/controllers#resource-controllers).
And also i want take your attention on how you called your controller. You should use CamelCase for naming your files (https://github.com/alexeymezenin/laravel-best-practices/blob/master/README.md).
There's no difference, but you might want to look in reosource routes and controller. Basically, laravel framework automatically creates routes and methods for controllers that you might need in your project. For example:
If you create a contoller like this:
php artisan make:controller RolesController --resource
and create a resource route like this:
Route::resource('/roles', 'RolesController ');
framework automatically crates this routes for you:
Verb Path Action Route Name
GET /roles index roles.index
GET /roles/create create roles.create
POST /roles store roles.store
GET /roles/{roles} show roles.show
GET /roles/{roles}/edit edit roles.edit
PUT|PATCH /roles/{roles} update roles.update
DELETE /roles/{roles} destroy roles.destroy
So you don't have to make your own routes and ask yourself if they are correct or not. Look into laravel official documentation for more info about this.

Laravel Backend Admin - Separate Laravel Install or Use only One Laravel Install?

I need structure tips before I create my personal website using Laravel 5.3.
Should I use a separate Laravel install for my subdomain backend to be safer or should I only use one Laravel install and do the routes below?
Which is the best practice and easier to maintain?
Should I use subdomain for my Backend Admin or just use sub-folder (www.domain.com/admin)
MY CURRENT STRUCTURE BELOW
Preferred URLs:
http://www.domain.com (Frontend)
http://admin.domain.com (Backend)
Controllers:
app\Http\Controllers\Admin\AdminController.php (Backend)
app\Http\Controllers\HomeController.php (Frontend)
Routes File:
Route::group(array('domain' => 'domain.com'), function() {
Route::get('/', 'HomeController#index');
});
Route::group(array('domain' => 'admin.domain.com'), function() {
Route::get('/', 'Admin\AdminController#index');
});
VHOST:
127.0.0.1 domain.com
127.0.0.1 admin.domain.com
Should I use a separate Laravel install for my subdomain backend to be
safer or should I only use one Laravel install and do the routes
below?
Separate the installation only if there exists a chance that you will move the admin to some other location later. If that is not the case better keep the everything under one installation, so that the dependencies will be same and you don't need to maintain the two configs, two models for every entity etc etc. Only thing you need to keep in mind is to structure the Admin & User routes separately with controllers in different folder which you have done already.
Which is the best practice and easier to maintain?
As explained above the easier way to maintain is to keep everything under one installation.
Should I use subdomain for my Backend Admin or just use sub-folder
That's up to you. But better the admin path a not-simply-guessable one. Something like domain.com/adm1n or adm1n.domain. com or something more complex.

how to use laravel illuminate in a custom project

I have a static site with a lot of pages. Now I got a new requirement. Client need a Client Area, I am thinking to use laravel Database Eloquent, Session, Form/html, Session and want to use them as alias like use in laravel/lumen. The problem is that I want static pages same as it is with .html extension, is there any solution? I want some packages with aliases to speed up.
I spent a complete day on Configuring Input and Eloquent but I wasn't able to setup to other packages. But I don't know how to set aliases and service providers. Any idea?
Specific:
I need Laravel Some packages
Session,
FileSystem
Mail
Input
Database
Html/Form,
Validation
I don't need others packages and need aliases same as laravel used in (config/app)
yes you can use laravel components outside laravel project please read the article : http://www.richardbagshaw.co.uk/using-illuminate-components/

Resources