16

I am using Laravel for building an App that helps Users find Service Providers. There will be 2 apps like Uber, 1 for the Users and 1 for the Providers. The user will make a request and depending on the request the selected Providers will receive a notification. Just like Uber.

The problem is, how should I design this. What I came up with:

  1. 2 APPS: Have 2 Laravel apps with common db. But how do I notify Providers when a User generates a request? Only the DB changes, so how do i tell Provider App that User App generated a request?

  2. Single App 2 FrontEnds: Have a single Laravel App and 2 Front ends. There will be separate apps on Play store but single Server App. How can I do this?

Is there a better solution to this approach? How does Uber do the same?

1
  • 1
    Just to help others with similar issues, I moved to Meteor instead of Laravel. In Meteor I made two completely different apps and connected them to the same DB. Whenever the DB changes, Meteor will reflect the changes to both clients. It uses websockets by default so all changes are pushed to clients. Its perfect for my scenario. Thanks Jul 14, 2015 at 10:43

5 Answers 5

8
+50

I would suggest you should use a given service like PubNub (see Demos).

That way you could save your Server-Development, there is also a Android-Example You simple use it within your APP like this:

dependencies {
    ....
    compile 'com.pubnub:pubnub:3.7.4'
    //'com.pubnub:pubnub-android-debug:3.7.+' For the debug version
}

and

import com.pubnub.api.*;
import org.json.*;

Pubnub pubnub = new Pubnub("demo", "demo");

try {
  pubnub.subscribe("my_channel", new Callback() {
      @Override
      public void connectCallback(String channel, Object message) {
          pubnub.publish("my_channel", "Hello from the PubNub Java SDK", new Callback() {});
      }

      @Override
      public void disconnectCallback(String channel, Object message) {
          System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
                     + " : " + message.getClass() + " : "
                     + message.toString());
      }

      public void reconnectCallback(String channel, Object message) {
          System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
                     + " : " + message.getClass() + " : "
                     + message.toString());
      }

      @Override
      public void successCallback(String channel, Object message) {
          System.out.println("SUBSCRIBE : " + channel + " : "
                     + message.getClass() + " : " + message.toString());
      }

      @Override
      public void errorCallback(String channel, PubnubError error) {
          System.out.println("SUBSCRIBE : ERROR on channel " + channel
                     + " : " + error.toString());
      }
    }
  );
} catch (PubnubException e) {
  System.out.println(e.toString());
}

If you are looking for ideas how Uber is doing this, look at the tutorial "The PubNub Connected Car Solution Kit"

So I hope I could answer, how Uber does this and how you can make it better :-)

1
  • 1
    oh, by the way: forgot PHP for things like that. It blocks a DB too long for multiple devices within distributed systems like this. Next to PubNub there are other distributors, but I mad very good experiences with the nice people when I developed for Tessel.io :-) ... yes you also can use Microcontrollers for your idea!
    – Danny
    Jul 9, 2015 at 9:16
5

I think a good solution would be putting all business logic into one Laravel application which is accessible via REST. So you don't have to update files twice.

The "real" apps only working as a middle tier and using this API.

For example in front you could setup Angular Apps. If you use nginx, you can define different locations per domain. This way all requests starting with "api" are routed to your Laravel application. The rest is routed to your static Angular App.

{
    listen 80;
    server_name customer.com;

    location /api{
        root /var/www/api;
    }

    location / {
        root /var/www/static/customer;
    }
}

{
    listen 80;
    server_name internalarea.com;

    location /api{
        root /var/www/api;
    }

    location / {
        root /var/www/static/restricted;
    }
}

https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

If you build your frontend apps also with Laravel, the API becomes a own URL which is used by the frontend systems. For doing this requests, I like using Zend\Http\Client which is very comfortable.

2
  • How will two different apps communicate? how can I notify the provider of an upcoming job? Jul 9, 2015 at 8:37
  • All data processing happens in the "API" app, the other apps are only facades for remote access which provide the user interface. If a request is send to the API system, it will send an email or something else to the providers. If you want to inform providers in"real time", you need to ask the API every some seconds if something happens or use a external system to establish websockets.
    – S.Löwe
    Jul 9, 2015 at 9:33
3

If you want to develop application for normar user and for provider.

Then I will suggest you to develop 2 seprate app and a single server (never create diffrent servers for any application)

Or you can assign user types at the time of registration.

2
  • Can you explain how will the apps communicate with the server and notify each other? Jul 9, 2015 at 8:35
  • You need to create total architechture of app, You can create APIs to to communicate with server.
    – Gaurav
    Jul 9, 2015 at 8:53
2

You should develop one common API and two apps like Uber. Or you could build only one app for both the vendor and the buyer like eBay. You should use a listener on your server code so whenever an event is triggered you should send such and such notifications. Take a look at listeners design pattern.

0

Since there is single (database) it is better to use single backend application. You can send the push notification to providers (android app) when user adds new request.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.