Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Consumer and Provider App architecture

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?

like image 969
rohitnaidu19 Avatar asked Jul 07 '15 06:07

rohitnaidu19


2 Answers

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 :-)

like image 113
Danny Avatar answered Sep 22 '22 17:09

Danny


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.

like image 29
S.Löwe Avatar answered Sep 25 '22 17:09

S.Löwe