PHPackages                             shipmate-io/laravel-shipmate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. shipmate-io/laravel-shipmate

ActiveLibrary[API Development](/categories/api)

shipmate-io/laravel-shipmate
============================

Interact with Shipmate from your Laravel code

3.0.0(2y ago)03.6k[3 PRs](https://github.com/shipmate-io/laravel-shipmate/pulls)MITPHPPHP ^8.0

Since Oct 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/shipmate-io/laravel-shipmate)[ Packagist](https://packagist.org/packages/shipmate-io/laravel-shipmate)[ Docs](https://github.com/shipmate-io/laravel-shipmate)[ RSS](/packages/shipmate-io-laravel-shipmate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (14)Used By (0)

Interact with Shipmate from your Laravel code
=============================================

[](#interact-with-shipmate-from-your-laravel-code)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require shipmate-io/laravel-shipmate
```

Job queue
---------

[](#job-queue)

Add a new queue connection to your `config/queue.php` file:

```
'shipmate' => [
    'driver' => 'shipmate',
    'default_queue' => 'default',
    'queues' => [
        'default' => [
            'name' => env('SHIPMATE_DEFAULT_JOB_QUEUE_NAME'),
            'worker_url' => env('SHIPMATE_DEFAULT_JOB_QUEUE_WORKER_URL'),
        ],
    ],
],
```

Update the `QUEUE_CONNECTION` environment variable:

```
QUEUE_CONNECTION=shipmate

```

Message queue
-------------

[](#message-queue)

The message queue are configured in the `config/message-queue.php` file.

```
return [

    /*
     * The message queues that are available to your service.
     */
    'queues' => [
        'default' => env('SHIPMATE_DEFAULT_MESSAGE_QUEUE_NAME'),
    ],

    /*
     * The file within your code base that defines your message handlers.
     */
    'message_handlers' => base_path('routes/messages.php'),

    /*
     * Whether to register the routes required to handle the messages from the message queues.
     */
    'register_routes' => true,

];
```

You can publish this file by running the following artisan command:

```
php artisan vendor:publish --tag="shipmate-config"
```

A message is a simple class that implements the `Shipmate\LaravelShipmate\MessageQueue\ShouldPublish` interface.

```
use Shipmate\LaravelShipmate\MessageQueue\ShouldPublish;

class UserCreated implements ShouldPublish
{
    public function publishOn(): string
    {
        return 'default';
    }

    public function publishAs(): string
    {
        return 'user.created';
    }

    public function publishWith(): array
    {
        return [
            'first_name' => 'John',
            'last_name' => 'Doe',
        ];
    }
}
```

To publish a message to the message queue, you can dispatch it using Laravel's event helper.

```
event(new UserCreated);
```

The message queue delivers this message to the other services in your application as an HTTP request. To accept this request, the package automatically registers the following routes in your service.

```
Route::post('shipmate/handle-message', [Shipmate\LaravelShipmate\MessageQueue\MessageQueueController::class, 'handleMessage']);
Route::post('shipmate/handle-failed-message', [Shipmate\LaravelShipmate\MessageQueue\MessageQueueController::class, 'handleFailedMessage']);
```

Next, the package looks in the `routes/messages.php` file of your service for a handler that corresponds with the type of the message. The contents of the file should look like this:

```
