demo-attachment-304-05-Featured

Wired.com focuses on how emerging technologies

Amazon, which already charges some of the world’s lowest fees for Prime Video in India, is going a step further to win more users in the world’s second largest internet market. The e-commerce giant on Saturday launched miniTV, an ad-supported video streaming service that is available within the Amazon shopping app and is “completely free.” miniTV is currently available only in India, Amazon said.

miniTV features web-series, comedy shows, and content around tech news, food, beauty, fashion “to begin with,” Amazon said. Some of the titles currently available have been produced by leading studios such as TVF and Pocket Aces — two of the largest web studios in India — and comedians such as Ashish Chanchlani, Amit Bhadana, Round2Hell, Harsh Beniwal, Shruti Arjun Anand, Elvish Yadav, Prajakta Koli, Swagger Sharma, Aakash Gupta and Nishant Tanwar.

“Viewers will be informed on latest products and trends by tech expert Trakin Tech, fashion and beauty experts such as Sejal Kumar, Malvika Sitlani, Jovita George, Prerna Chhabra and ShivShakti. Food lovers can enjoy content from Kabita’s Kitchen, Cook with Nisha, and Gobble. In the coming months, miniTV will add many more new and exclusive videos,” the company added, without sharing its future roadmap plans. (Amazon began integrating reviews and other web clippings — from media houses — on its shopping service in India for more than two years ago.)

miniTV is currently available on Amazon’s Android app, and will arrive on the iOS counterpart and mobile web over the coming months, Amazon said.

Amazon’s move follows a similar step by Walmart’s Flipkart, the company’s marquee rival in India, which rolled out video streaming service within its app in 2019. In recent years, scores of firms in India including Zomato have explored adding a video streaming offering to their own apps.

Amazon has also aggressively pushed to expand its Prime Video offerings in India in recent quarters. The company — which partnered with Indian telecom network Airtel earlier this year to launch a new monthly mobile-only, single-user, standard definition (SD) tier (for $1.22) — has secured rights to stream some cricket matches in the country. Amazon also offers Prime Video as part of its Amazon Prime subscription in India.

demo-attachment-898-21
demo-attachment-2142-Writer

Mark Spenser |

Mark Spenser is a local NY resident and an avid geek. When he's not rediscovering his island state, he enjoys spending time at TechPhlox and review latest tech's world products and news. You can follow him on Twitter @MarkSpenser

RELATED ARTICLES

demo-attachment-301-04-Featured

ounded almost 30 years ago, Zdnet is a business technology

Amazon, which already charges some of the world’s lowest fees for Prime Video in India, is going a step further to win more users in the world’s second largest internet market. The e-commerce giant on Saturday launched miniTV, an ad-supported video streaming service that is available within the Amazon shopping app and is “completely free.” miniTV is currently available only in India, Amazon said.

miniTV features web-series, comedy shows, and content around tech news, food, beauty, fashion “to begin with,” Amazon said. Some of the titles currently available have been produced by leading studios such as TVF and Pocket Aces — two of the largest web studios in India — and comedians such as Ashish Chanchlani, Amit Bhadana, Round2Hell, Harsh Beniwal, Shruti Arjun Anand, Elvish Yadav, Prajakta Koli, Swagger Sharma, Aakash Gupta and Nishant Tanwar.

“Viewers will be informed on latest products and trends by tech expert Trakin Tech, fashion and beauty experts such as Sejal Kumar, Malvika Sitlani, Jovita George, Prerna Chhabra and ShivShakti. Food lovers can enjoy content from Kabita’s Kitchen, Cook with Nisha, and Gobble. In the coming months, miniTV will add many more new and exclusive videos,” the company added, without sharing its future roadmap plans. (Amazon began integrating reviews and other web clippings — from media houses — on its shopping service in India for more than two years ago.)

miniTV is currently available on Amazon’s Android app, and will arrive on the iOS counterpart and mobile web over the coming months, Amazon said.

Amazon’s move follows a similar step by Walmart’s Flipkart, the company’s marquee rival in India, which rolled out video streaming service within its app in 2019. In recent years, scores of firms in India including Zomato have explored adding a video streaming offering to their own apps.

Amazon has also aggressively pushed to expand its Prime Video offerings in India in recent quarters. The company — which partnered with Indian telecom network Airtel earlier this year to launch a new monthly mobile-only, single-user, standard definition (SD) tier (for $1.22) — has secured rights to stream some cricket matches in the country. Amazon also offers Prime Video as part of its Amazon Prime subscription in India.

demo-attachment-898-21
demo-attachment-2142-Writer

Mark Spenser |

Mark Spenser is a local NY resident and an avid geek. When he's not rediscovering his island state, he enjoys spending time at TechPhlox and review latest tech's world products and news. You can follow him on Twitter @MarkSpenser

RELATED ARTICLES

demo-attachment-296-03-Featured

TheNextWeb brings insights to the world of technology

Amazon, which already charges some of the world’s lowest fees for Prime Video in India, is going a step further to win more users in the world’s second largest internet market. The e-commerce giant on Saturday launched miniTV, an ad-supported video streaming service that is available within the Amazon shopping app and is “completely free.” miniTV is currently available only in India, Amazon said.

miniTV features web-series, comedy shows, and content around tech news, food, beauty, fashion “to begin with,” Amazon said. Some of the titles currently available have been produced by leading studios such as TVF and Pocket Aces — two of the largest web studios in India — and comedians such as Ashish Chanchlani, Amit Bhadana, Round2Hell, Harsh Beniwal, Shruti Arjun Anand, Elvish Yadav, Prajakta Koli, Swagger Sharma, Aakash Gupta and Nishant Tanwar.

“Viewers will be informed on latest products and trends by tech expert Trakin Tech, fashion and beauty experts such as Sejal Kumar, Malvika Sitlani, Jovita George, Prerna Chhabra and ShivShakti. Food lovers can enjoy content from Kabita’s Kitchen, Cook with Nisha, and Gobble. In the coming months, miniTV will add many more new and exclusive videos,” the company added, without sharing its future roadmap plans. (Amazon began integrating reviews and other web clippings — from media houses — on its shopping service in India for more than two years ago.)

miniTV is currently available on Amazon’s Android app, and will arrive on the iOS counterpart and mobile web over the coming months, Amazon said.

Amazon’s move follows a similar step by Walmart’s Flipkart, the company’s marquee rival in India, which rolled out video streaming service within its app in 2019. In recent years, scores of firms in India including Zomato have explored adding a video streaming offering to their own apps.

Amazon has also aggressively pushed to expand its Prime Video offerings in India in recent quarters. The company — which partnered with Indian telecom network Airtel earlier this year to launch a new monthly mobile-only, single-user, standard definition (SD) tier (for $1.22) — has secured rights to stream some cricket matches in the country. Amazon also offers Prime Video as part of its Amazon Prime subscription in India.

demo-attachment-898-21
demo-attachment-2142-Writer

Mark Spenser |

Mark Spenser is a local NY resident and an avid geek. When he's not rediscovering his island state, he enjoys spending time at TechPhlox and review latest tech's world products and news. You can follow him on Twitter @MarkSpenser

RELATED ARTICLES

demo-attachment-293-02-Featured

Hacker Noon covers a range of topics across the tech sector

Amazon, which already charges some of the world’s lowest fees for Prime Video in India, is going a step further to win more users in the world’s second largest internet market. The e-commerce giant on Saturday launched miniTV, an ad-supported video streaming service that is available within the Amazon shopping app and is “completely free.” miniTV is currently available only in India, Amazon said.

miniTV features web-series, comedy shows, and content around tech news, food, beauty, fashion “to begin with,” Amazon said. Some of the titles currently available have been produced by leading studios such as TVF and Pocket Aces — two of the largest web studios in India — and comedians such as Ashish Chanchlani, Amit Bhadana, Round2Hell, Harsh Beniwal, Shruti Arjun Anand, Elvish Yadav, Prajakta Koli, Swagger Sharma, Aakash Gupta and Nishant Tanwar.

“Viewers will be informed on latest products and trends by tech expert Trakin Tech, fashion and beauty experts such as Sejal Kumar, Malvika Sitlani, Jovita George, Prerna Chhabra and ShivShakti. Food lovers can enjoy content from Kabita’s Kitchen, Cook with Nisha, and Gobble. In the coming months, miniTV will add many more new and exclusive videos,” the company added, without sharing its future roadmap plans. (Amazon began integrating reviews and other web clippings — from media houses — on its shopping service in India for more than two years ago.)

miniTV is currently available on Amazon’s Android app, and will arrive on the iOS counterpart and mobile web over the coming months, Amazon said.

Amazon’s move follows a similar step by Walmart’s Flipkart, the company’s marquee rival in India, which rolled out video streaming service within its app in 2019. In recent years, scores of firms in India including Zomato have explored adding a video streaming offering to their own apps.

Amazon has also aggressively pushed to expand its Prime Video offerings in India in recent quarters. The company — which partnered with Indian telecom network Airtel earlier this year to launch a new monthly mobile-only, single-user, standard definition (SD) tier (for $1.22) — has secured rights to stream some cricket matches in the country. Amazon also offers Prime Video as part of its Amazon Prime subscription in India.

demo-attachment-898-21
demo-attachment-2142-Writer

Mark Spenser |

Mark Spenser is a local NY resident and an avid geek. When he's not rediscovering his island state, he enjoys spending time at TechPhlox and review latest tech's world products and news. You can follow him on Twitter @MarkSpenser

RELATED ARTICLES

Eaton’s network rack system maximizes data center cable efficiency and flexibility

Power management company Eaton launched a flexible and space efficient rack and cable management solution for high-density network equipment and data center applications. Eaton’s B-Line series High-Density Network Rack System (HDNR) uses Eaton’s patented 4-Dimension structural support system to enable an increase in cable management capacity compared to competing vertical cable managers.

Eaton’s HDNR system offers innovative open-frame rack solutions with a full line of rack, cable management, power, and air flow accessories which deliver industry-leading flexibility, density, and reliable mounting of critical network equipment.

“Eaton is revolutionizing the traditional rack system to provide customers with a new standard for functionality and flexibility,” said Tara Walker, product manager, Rack and Runway products, Eaton. “The new HDNR is specifically designed to meet the evolving needs of today’s data center and network environments while creating a more cost effective infrastructure.”

To help reduce costs and preserve valuable data center floor space, the HDNR’s unique cable management design supports its maximum cable capacity without increases in physical footprint. The HDNR achieves maximum density with an increase in total cable capacity versus leading competitor high-density rack systems.

Preserving uptime during maintenance or system changes, the system is designed with low-profile in-rack electrical power distribution unit (ePDU) mounting that allows users to remove equipment from the back of the rack without disconnecting power.

The HDNR system also features fully adjustable rails designed to meet diverse and changing equipment, cabling and power needs both before and after installation. Multiple ePDU mounting options offer versatility when system requirements are unknown and a fully adjustable rack waterfall is compatible with Eaton’s complete range of cable management and rack accessories.

To provide reliable protection for hardware investments, the HDNR system is engineered with a 2,200-pound load rating and is both Underwriters Laboratories (UL) and California Hospital Office of Statewide Health Planning and Development (OSHPD) pre-approved. To provide additional safety, all HDNR configurations feature a self-bonding grounding system and floor anchor holes.

Eaton
www.eaton.com/hdnr

Patch Panel vs Switch: What’s the Difference?

In network setups we see everything is plugged into a switch, but before that fiber cables are also connected to another supply — patch panel. Thus one question is often confusing: patch panel vs switch: What’s the difference and what’s the significant function of them respectively?

What Is Patch Panel?

Patch panel (fiber optic patch panel, fiber optic enclosure) is a terminate unit of network ports centralized together. It is a cable management solution component used to organize fiber cables and keep everything neat for a clean wiring closet. In data centers, a mass of cable wires scattering all over and mixed together can be bothersome, in this case a patch panel is indispensable and rather helpful. It not only offers ease of management, but also protect the terminations from being knocked. Besides the fiber optic patch panel, other cable management accessories including cable ties and cable labels are also used to keep cables tidy and easy for identification.

Figure 1: This photo shows the application of patch panel by FS.COM for cable management in a data center.

What Is Switch?

Switch, commonly known as network switch, is an appliance in a data center that connects all devices (such as PCs and servers) as a whole to achieve intercommunication and data sharing between different network devices. It channels the incoming data from multiple input ports to the specific output port so as to deliver the data toward its destination. In Ethernet LAN or WAN, modern network switch usually determines which output port to use by network address.

Figure 2: This photo shows the application of network switch by FS.COM in a data center.

Patch Panel vs Switch: What’s the Difference?

Table below shows the main difference of patch panel vs switch.

Role in Date Center

Comparing patch panel vs switch, we can make the following conclusion. Patch panel is nothing but an essential cable management tool, which exerts no functional influence to the performance of data transmission. However, a switch is an irreplaceable functional supply in network setups.

Why Patch Panel Is Commonly Set Up in Network Installation?

As mentioned above, patch panel has no effect on the data transmission process. Can it be omitted in fiber optic cabling? Or can wires just directly plugged to a switch? The answer is yes when you just deal with several fiber cables. However, Ethernet patch panel is a must in data centers where there are a large number of Ethernet drops. No doubt you don’t want to see all the things tangled together. A patch panel in place provide ease management of classification, maintenance, repair, installation and upgrades.

Conclusion

This article gave an brief introduction to patch panel and switch respectively and then discussed the differences between them. Patch panel vs switch : what’s the difference, and why is a patch panel commonly set up in network installation whereas a switch is already used? Can you answer these questions now? Simply put, patch panel is an essential cable management tool whereas network switch is a significant functional supply in data center. Both of them play important role in their respective positions.

Sumber: https://medium.com/@sylvieliu66/patch-panel-vs-switch-whats-the-difference-670625b17783

How PHP and Nginx work together (Image credit: DataDog)

How to setup Nginx to run PHP/Laravel API with frontend app on same domain

There are multiple ways of deploying this kind of applications and here I will describe my way of doing it. Lately, many applications separate frontend and backend parts so we can observe them as two projects. We could have Laravel API and Angular/React/Vue on the other side. If we have this project structure then our frontend (eg. Vue) is purely static app.

Running npm run build is going to generate dist directory which contains our entire application which we can then serve using Web server.

As for the PHP part, we want to use FastCGI Process Manager (FPM). This is a topic in itself but in short FPM will handle PHP files much more efficiently and thus improve performance and enable a higher load.

How PHP and Nginx work together (Image credit: DataDog)
How PHP and Nginx work together (Image credit: DataDog)

Many developers will serve frontend part on www.example.com and backend part on www.api-example.com. This is pretty simple to configure but when I wanted to serve Vue app on www.example.com and my API on www.example.com/api I ran into some problems. If you just bought server and don’t have a domain yet, this is the way you can deploy your app. After some time this is the configuration I decided to use

server {
    listen 80;
    server_name 147.242.153.77; # fake IP address
    root /home/myfolder/example/html; #path to static directory
    
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    
    index index.html index.htm index.php;
    charset utf-8;
    
    location / {
            try_files $uri $uri/ /index.html;
    }
    
    location /api {
            alias /home/myfolder/example-api/public;
            try_files $uri $uri/ @laravelapi;
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
                    fastcgi_param SCRIPT_FILENAME $request_filename;
            }
    }

    location @laravelapi {
            rewrite /api/(.*)?$ /api/index.php?$is_args$args last;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    error_page 404 /index.php;

    location ~ /\.(?!well-known).* {
            deny all;
        }
}

We set root directive to our frontend app. Every request is going to hit our first location block if it doesn’t start with /api and it is going to execute index.html from Vue static directory.

Request made for /api/users is a little bit more complicated. It is going to hit second location block. Then we are using alias to set correct path to our API.

Note: alias directive doesn’t append the location part. If we used root instead it would try to access /home/myfolder/example-api/public/api and that is not what we want.

The try_files means when you receive a URI that’s matched by this block try $uri first, eg. /api/images/image.jpg , Nginx will try to serve image.jpg file inside /home/myfolder/example-api/public/images. Then it will try to serve whole folder /images.

Last option is a fallback option which will redirect request to the named location @laravelapi. Inside this block we will rewrite /api/users into /api/index.php.

Flag last stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI.

Because of the new URI /api/index.php, this time we will finally hit regex location block ~ .php$ that is going to pass processing of the /home/myfolder/example-api/public/index.php script to FPM.

IMPORTANT: With this configuration our Laravel application is deployed on 147.242.153.77/api so we can remove route prefix /api from Laravel’s RouteServiceProvider.php . If we hadn’t done that we would need to send requests to /api/api/users to get a response, otherwise we would get 404.

How to simply avoid “else” in PHP and other programming languages

3 years ago, I was installing PHP Mess Detector for the first time on my Laravel application and after testing somes rules I fall on one rule that changed my programing vision since :

“Else is never necessary and you can simplify the code to work without else.”

https://phpmd.org/rules/cleancode.html#elseexpression

The documentation has no hint on how to process to deal with it, normal, it’s not his purpose. However, by forcing myself not to use the “else”, and after reviewing code of my team (about ten people with different level programming and different framework) I noticed that it was the same cases that kept coming back where we let ourselves be tempted to use it. Let see when and how to bypass them !


First, the very worst use case that I could see:

if ($myCondition) {
  // do NOTHING !
} else { 
  // do something
}

So, we are already told that the “else” is never necessary and in addition we find portions of code where it is the “if” that becomes completely unused instead … That’s ironic ! Somes dudes losed her head here .

It’s the worst and the easiest to deal with at the same time, just reverse the condition:

if (! $myCondition) {
  // do something
}

The other frustrating use case is when we use the “return” statement:

function myMethod()
{
  if ($condition) {
    // do something
    return true;
  } else {
    // do something else
    return false;
  }
}

I think that we tend to forget that a “return” abort the method and that if we has a “return” inside an “if” we will never go into the rest of the code, we can therefore simplify by removing the “else” and reindent (Which is also something important !):

function myMethod()
{
  if ($condition) {
    // do something
    return true;
  }
  // do something else
  return false;
}

We can apply this logic with other “breaking” statement, like “continue” in “foreach”

foreach ($array as $value) {
  if ($condition) {
    // do something
    continue;
  } else {
    // do something else
  }
}

foreach ($array as $value) {
  if ($condition) {
    // do something
    continue;
  }
  // do something else
}

The ternary and null coalescing operators

often we use the if / else to assign variables like this:

if ($condition) {
  $var = 'Hello';
} else {
  $var = 'World';
}

Here, it’s not complicate to deal with it but the approach can change according to the context, we can do:

$var = 'World';
if ($condition) {
  $var = 'Hello';
}

or, I think it’s better, use a ternary operator :

$var = $condition ? 'Hello' : 'World';

In PHP, if our condition is to verify if some variable exist and is not null, for assign it, we can use the null coalescing operators since php 7.x :

$var = $canNotExist ?? ‘hello world’;

so if $canNotExist is null or undefined, $var would be ‘Hello World’, if he is ‘false’ or empty ($canNotExist = ‘’), it will be returned anyway.

We can also use method inside our operators:

return CONDITION ? $users->getAll() : $users->getSomes();

And also indent like this when the lines becomes to long:

return (CONDITION && CONDITION2)
  ? $users->myMethodNameABitTooMuchLong()
  : $users->myOtherMethodNameTooLong();

Note that we can definitely use the ternary for returning boolean inside a fonction but there is still a small tips sometimes forgotten …

function myMethod()
{
  return $shouldReturnTrue ? true : false;
}

We can simply return the condition directly like that!

function myMethod()
{
  return $shouldReturnTrue;
}

This behaviour can depend on the contexte or the langage, see this example with the ‘or’ operator

function myMethod()
{
  $a = null;
  $b = "something";
  return $a || $b; 
}

in PHP, myMethod will return true because $b worth “something” but in other langage like JavaScript, myMethod will return the string “something”, the variable which is true for him … subtle, isn’t it?

Laravel Eloquent and the “if” statement

It’s a small bonus content for this articles, since we saw we don’t have really need of the “else” I think funny to know that Eloquent help us to also avoid the “if” in your code with the method when() that seem really pretty since PHP 7.4 and the coming of arrow function, example:

function getUsers(Request $r)
{
  $users = app(User::class);
  if ($r->created_at) {
    $users->where('created_at', $r->created_at);
  }
  if ($r->username) {
    $users->where('username', $r->username);
  }
  return $users->get();
}

That a common use case of Eloquent and filter Request, since we have the arrow function we can simplify like this (We can use the when() before, but I consider him really nice since):

function getUsers(Request $r)
{
    return User::when(CONDITION, CLOSURE)
        ->when($r->username, fn($q)=>$q->where('username', $r->username))
        ->get();
}

Conclusion

Why avoid “else” in your code ? It work, it was made to be used, it intuitive … Personnaly, i was first interested by this concept like “It’s true ? we really don’t need this ?” and after practice (it’s a challenge in the beginning) I realized that 99% of the times when I deemed it necessary, I don’t use it anymore … Yes there is still some time when I cannot allow to fully refactor legacy code due to lack of time (or rather budget). But now I find better clarity in my code, more refined and with above all: only useful code, because the “else” sometimes encourages redundant instructions, however small it may be. And it may seem trivial, but I read the “else”, unconsciously or not. It is a visual load that can be prevented as for the “parasitic characters” in the writing of Curriculum Vitae, where we are told that the recruiter takes less than 1 minute to read and that it is then necessary to eliminate everything which is not useful and play with formatting to guide the reader. In short, without it, my code works just as well, it’s shorter and is a little more maintainable, so I do without it. There are plenty of other ways to refactoring your code, you just have to take a look at https://refactoring.com/catalog/ to see some, but this one, I found it particularly not intuitive, “don’t use basic programming functionality?” and yet it’s really easy points to earn.

Sumber: https://thomas-sanctorum.medium.com/how-to-simply-avoid-else-in-php-and-others-programming-language-ccd6a07c4e1

reppattern

Repository & Service Pattern in Laravel

Are you starting off your new Laravel project? Take a moment to plan ahead!

Structuring your application is the key to ensuring that you don’t get confused about your own application in the future, making it easy to create new features and understand your code. In this talk I will show practical examples of the repository and service pattern in a Laravel application.

Please note: The repositories shown below aren’t decoupled from Eloquent models. This means that we are returning Eloquent objects from our methods within the repositories and not domain objects which a true repository pattern would. More will be explained later in the repositories section.

Below is an basic example of the Users model folder.

App\Modules\Users folder
App\Modules\Users folder

Folders have been created for each class type, as with every new feature comes a new class. It may not be on your mind right now to plan out your class locations, but seeing unorganised code months down the line will make you reconsider your choices when you started.

Repositories

The repository is a layer between the domain and data layers of your application with an interface to perform create, read, update and delete CRUD operations.

As mentioned previously, the repositories shown are coupled to Eloquent models, and so they aren’t returning true domain objects. A true repository pattern would allow you to switch between different ORMs, such as changing from Eloquent to Doctrine without affecting the service layer. This can be achieved by keeping both Eloquent Models and Doctrine Entities within your repositories and returning the same domain objects from their methods. This is entirely up to you and if you feel that you would need to change ORM in the future, but for most Laravel projects this can be overkill as you may never need to change ORM.

By using repositories in your application, you allow CRUD operations for an object to be handled by one class which can then be injected into other areas of your code. Below is a basic example of a user repository.

<?php
declare(strict_types=1);
namespace App\Modules\Users\Repositories;

use App\Modules\Users\User;
use Illuminate\Database\Eloquent\Collection;

class UserRepository
{
    /**
     * @return Collection
     */
    public function getUsers(): Collection
    {
        return User::all();
    }

    /**
     * @param int $userId
     * @return User
     */
    public function getUserById(int $userId): User
    {
        return User::find($userId);
    }

    /**
     * @param string $email
     * @return User
     */
    public function getUserByEmail(string $email): User
    {
        return User::where('email', $email)->first();
    }
}

If we ever need one of these searches in another class, we can simply embed this repository and use the relative function.

Services

A service applies the business logic of your application. It simply performs the a set task (e.g. calculating a loan, updating a user) using the information provided, using any repositories or other classes you have created outside of the service.

Say we would like to allow a user to update their email. We can pass the request over to the UpdateUserService in the class, which can handle the business logic. This logic includes ensuring the email is valid, sending a verification email to the user whilst also creating a log in the user_logs table in the database to state that the user has been updated successfully.

What if we then wanted a ‘Change Password’ feature on the app?

use App\Modules\Users\Services\UpdateUserService;

Inject this class into your code, use the update function within, and that’s it.

The idea of the repository and service pattern are to keep the business logic (services) and the data access logic (repositories) of your app contained in their own sections.

Repositories & Services in a Controller

By keeping to this pattern, an example controller would be below.

<?php

declare(strict_types=1);

namespace App\Http\Controllers\User;

use App\Http\Requests\Users\CreateUserRequest;
use App\Modules\Users\Repositories\UserRepository;
use App\Modules\Users\Services\CreateUserService;
use App\Http\Responses\Users\UserResponse;
use App\Http\Responses\Response;

class UserController
{
    /**
     * @var UserRepository
     */
    private UserRepository $repository;

    /**
     * @param UserRepository $repository
     */
    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * @return Response
     */
    public function getUsers(): Response
    {
        return new Response(UserResponse::many($this->repository->getUsers()->all()));
    }

    /**
     * @param int $userId
     * @return Response
     */
    public function getUserById(int $userId): Response
    {
        return new Response(UserResponse::one($this->repository->getUserById($userId)));
    }

    /**
     * @param CreateUserRequest $request
     * @param CreateUserService $service
     * @return Response
     */
    public function createUser(CreateUserRequest $request, CreateUserService $service): Response
    {
        $user = $service->create(
            $request->get('name'),
            $request->get('email'),
            $request->get('password')
        );
        
        return new Response(UserResponse::one($user));
    }
}

As you can see, no logic that the service should handle is contained in the controller, hence making it easy to read. Also, no data-access logic is handled by the controller.
By sticking to this logic, projects can remain easy to read. The example below shows a loan calculator within a finance app with the same structure as above.

App\Modules\Loans folder
App\Modules\Loans folder
App\Modules\Loans folder

Furthermore, the application above uses Doctrine entities instead of Eloquent models. Although the ORM is different as discussed prior, the structure can be used the exact same, and can make it easy for any new developer looking at your code to understand what is happening.

Be sure to give claps if you found this article useful!

Sumber: https://joe-wadsworth.medium.com/laravel-repository-service-pattern-acf50f95726