How to update data in the application on request?

There is a backend for mobile applications on Laravel which receives the update request data in json format
'data': [
 {'table': 'Product', 'updated_at': <timestamp>}

The backend fetches all the data from the passed-in table that are specified in the same fresh updated_at of timestamp and return abom
public function handle()
 $requestData = request('data');

 $responseData = [];

 foreach ($requestData as $item) {
 $model = "\\App\\" . $item['table'];
 $updated = $item['updated_at'];

 $collection = $model::where('updated_at', '>', $updated)->get();

 if ($collection->count()) {
 $maxUpdatedAt = $collection->pluck('updated_at')->max();

 $responseData[] = [
 'updated_at' => $maxUpdatedAt,
 'table' => $item['table'],
 'data' => $collection->toArray()


 $response = ['action' => 'update', 'data' => $responseData];

 return response()->json($response);

The question arises - what to do with the huge amount of queries? Caching in this case is probably not suitable. What decisions are suitable for these tasks? Read about Broadcasting, but it's a slightly different approach and can it be used in this case?
March 23rd 20 at 19:29
1 answer
March 23rd 20 at 19:31
You obviously rolled somewhere when I started to do one query to retrieve data from several tables.

1) it is Better to stick to the resource approach (RESTful API), there will be no such problems.

In Laravel has built-in methods for implementing RESTful APIs, such as resource-controllers (

With the RESTful approach, you will need to do 1 query for each table - it should not cause problems in most cases. If the number of tables you have great - then, most likely you that that is not so designed or you need to consider another type of database (maybe ClickHouse? ).

2) To standardize the requests and responses use
There's a good packages: (the backend) and (JS front, can be used even in ReactNative).
If you find this too easy, look in the direction of GraphQL.

Find more questions by tags Laravel