PHP code example of lucid-arch / laravel-microservice

1. Go to this page and download the library: Download lucid-arch/laravel-microservice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lucid-arch / laravel-microservice example snippets


public function handle()
{
    return [
        ['name' => 'John Doe'],
        ['name' => 'Jane Doe'],
        ['name' => 'Tommy Atkins'],
    ];
}

use App\Data\Models\User;

class GetUsersJob extends Job
{
    private $limit;

    public function __construct($limit = 25)
    {
        $this->limit = $limit;
    }

    public function handle(User $user)
    {
        return $user->take($this->limit)->get();
    }
}

// ...
use App\Domains\User\GetUsersJob;
use App\Domains\Http\RespondWithJsonJob;
// ...
public function handle(Request $request)
{
    $users = $this->run(GetUsersJob::class);

    return $this->run(new RespondWithJsonJob($users));
}

// ...
use App\Features\ListUsersFeature;
// ...
class UserController extends Controller
{
    public function index()
    {
        return $this->serve(ListUsersFeature::class);
    }
}

Route::get('/users', 'UserController@index');

use Illuminate\Support\Facades\Event;
use Lucid\Foundation\Events\FeatureStarted;
use Lucid\Foundation\Events\OperationStarted;
use Lucid\Foundation\Events\JobStarted;

Event::listen(FeatureStarted::class, function (FeatureStarted $event) {
    // $event->name
    // $event->arguments
});

Event::listen(OperationStarted::class, function (OperationStarted $event) {
    // $event->name
    // $event->arguments
});

Event::listen(JobStarted::class, function (JobStarted $event) {
    // $event->name
    // $event->arguments
});