3

I am currently working on a Laravel 5.1 project which involves a public section and a admin section. When googling around the issue I was having, I came across this stack post managing user role log in. Where the first post recommends.

Admin and Users in the same laravel app is a bad idea simply because the app will share the same session and storage information. There will be a myriad of egde cases that will cause information to bleed through any logic "walls" you set up and you'll end up spending way too much time patching those bleeds. What you really want to do is set up separate laravel applications for each: admin.project.com & project.com. That way you get two separate sessions and storage. All you need to do is ensure that the databases you need are setup in both database.php config files. You can even host BOTH projects on the same server with separate deployments, listening to different ports. TRUST ME this is the best way to go.

Could someone explain in detail how it could be done? I mean how should I set up my project. I know It is easy for them to share the same DB and setting up that would easy. First question, how can I have URLs admin.mysite.com as my admin section and www.mysite.com as my public section for my 2 apps Also how to set it up in Azure as a web app? I got my one app I currently have working on Azure ( no 5.1 guides on the internet, got it deploying somehow).

So could someone explain in detail how the project setup should like and how it should be done? Could not find guides for Laravel 5.1 and since 5.1 setup is different from 5 and 4.* I'm not sure how to continue.

Community
  • 1
  • 1
DarkFeud
  • 181
  • 2
  • 16
  • Personally disagree with this. Properly managed authorisation and access privileges will (have to) work. Its principally the same as having a role/access hierarchy for your users. If you cant rely on that to work then the whole app is broken. I have had a lot of success using the awesome Sleeping-Owl Admin package that has its own authorisation which deals with most of the issues described http://sleeping-owl.github.io/ – Mike Miller Oct 30 '15 at 12:23
  • @MikeMiller So how would you handle different user types using the same login? rewriting the redirect path according to the user type like the link I posted above suggests or what would you recommend? – DarkFeud Oct 30 '15 at 12:46
  • So if I understand you want to have users that hold both admin and user roles? This wouldnt be possible using sleeping owls package as admin users are completely separated (different auth, session namespace and db table). You just want a role/access hierarchy. Protect your routes and only allow users with the right roles to access them. try this package maybe https://github.com/romanbican/roles. I used a while ago for something simple and it worked pretty well – Mike Miller Oct 30 '15 at 13:36
  • Right now I am using middleware to protect my routes @MikeMiller – DarkFeud Oct 30 '15 at 13:46
  • Out of the box? Check the middleware provided in the package above it will give you some idea – Mike Miller Oct 30 '15 at 14:51

1 Answers1

1

Per your description, it seems you need to deploy 2 apps with custom domains. If so, I think to deploy your admin and user apps separately on 2 Azure Web Apps services. Which is benefit for management, deployment and scaling for each side of your applications. To configure subdomains to your site, you can refer to Azure Websites and wildcard domains and Mapping a custom subdomain to an Azure Web App (Website).

If you insist on deploy 2 apps on a single Azure Web Apps Service, you can try it with URL rewriting in IIS Web.config, E.g.

      <rule name="RewriteRequestsAdmin" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
              <add input="{HTTP_HOST}" pattern="^admin\.XXXX\.com$"/>
          </conditions>
          <action type="Rewrite" url="AdminApp/public/index.php/{R:0}" />
        </rule>
        <rule name="RewriteRequestsUser" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
          </conditions>
          <action type="Rewrite" url="UserApp/public/index.php/{R:0}" />
        </rule>
      </rules>

To deploy your local laravel project to Azure Web Apps, you can use Git or FTP tools, please refer to Create a PHP-MySQL web app in Azure App Service and deploy using Git. But by default, the dependence folder vendor and composer files will not be deployed on Azure with project, so we have to login KUDU console site of your Azure Web Apps to install the dependences. You can install composer in site extensions tab of your KUDU console site which the URL should be https://<your_site_name>.scm.azurewebsites.net/SiteExtensions/#gallery then run command composer install in your app root directory.

Additionally, you can simply leverage cmdlet on your KUDU console site, which URL should be https://<your-website-name>.scm.azurewebsites.net/DebugConsole, run the following commands:

cd site\wwwroot 
curl -sS https://getcomposer.org/installer | php 
php composer.phar install

For deployment laravel on Azure, you can refer to the answer of laravel 5.1 on windows azure web application for more information.

Community
  • 1
  • 1
Gary Liu
  • 13,758
  • 1
  • 17
  • 32