简体   繁体   中英

How to create two laravel projects (on same server) with all files shared except resources (views) folder

I want to create two laravel projects on same server with almost all files common/shared (like symlinks) except resources folder. In simple terms, I just want to create mobile site for existing desktop version. So is there any way to use all files of desktop version except views. If not then atleast controllers, routes and models.

One way you could do that is to create APIs say on your main laravel app in your web.php folder like:

Route::get('/api/get/post', 'MainController@index');

so in your other Laravel app, you could call routes to it but have it be a separate view.

However by using the backend of project 1, you really don't need a backend for project 2 unless you want to use the blade templating engine.

I think a better option that would improve the user experience is to just have one laravel project and create a separate view with a separate URL.

I am assuming you need a complete re-write for mobile that can not be reasonably done with a responsive design. If so you redirect on mobile and change relevant links to mobile views.

if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i)) {
  window.location.replace("/mobile/page"); 

 document.getElementById("btn-link").setAttribute('href', '/mobile/page');
 <a href="https://example.com/desktop/page" id="btn-link">Click Me!</a>

The downside to reloading the your page is that it will have to load your original page assets and then reload another set of assets when you redirect it.

To get away from this you could write a mobile html in a different blade.php file but have it set to display: none;. then if the javascript sees the device is a mobile device is will toggle the display for the desktop and mobile versions.

However I would question why your mobile site needs to be so different from your desktop environment that a responsive design can't handle it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM