PHP code example of patrickquijano / laravel-mediator
1. Go to this page and download the library: Download patrickquijano/laravel-mediator 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/ */
patrickquijano / laravel-mediator example snippets
namespace App\Commands;
use LaravelMediator\Abstracts\Buses\Command;
class MyCommand extends Command
{
public function __construct(public string $data)
{
}
}
namespace App\Queries;
use LaravelMediator\Abstracts\Buses\Query;
class GetUserDataQuery extends Query
{
public function __construct(public int $userId)
{
}
}
namespace App\Handlers;
use LaravelMediator\Abstracts\Buses\Handlers\CommandHandler;
class MyCommandHandler extends CommandHandler
{
public function handle(MyCommand $command): void
{
// Handle the command
}
}
namespace App\Handlers;
use LaravelMediator\Abstracts\Buses\Handlers\QueryHandler;
class GetUserDataQueryHandler extends QueryHandler
{
public function handle(GetUserDataQuery $query): array
{
// Fetch user data and return it
}
}
use Illuminate\Foundation\Application;
return Application::configure(basePath: dirname(__DIR__))
->withEvents([
__DIR__.'/../app/Handlers',
]);
use LaravelMediator\Facades\CommandBus;
CommandBus::dispatch(new MyCommand('data'));
use LaravelMediator\Facades\QueryBus;
$userData = QueryBus::dispatch(new GetUserDataQuery(123));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.