PHP code example of shipmate-io / laravel-shipmate

1. Go to this page and download the library: Download shipmate-io/laravel-shipmate 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/ */

    

shipmate-io / laravel-shipmate example snippets


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

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 

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',
        ];
    }
}

event(new UserCreated);

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



return [

    'user.created' => HandleUserCreatedMessage::class,

    'user.deleted' => [HandleUserDeletedMessage::class, 'handle'],

];

    'user.created' => HandleUserCreatedMessage::class,
    

    use Shipmate\Shipmate\MessageQueue\Message;
   
    class HandleUserCreatedMessage
    {
        public function __invoke(Message $message): void
        {
            $firstName = $message->payload['first_name'];
   
            //
        }
    }
    
    class HandleUserCreatedMessage
    {
        public function handle(Message $message): void
        {
            $firstName = $message->payload['first_name'];
   
            //
        }
    }
    
    class HandleUserCreatedMessage
    {
        public function execute(Message $message): void
        {
            $firstName = $message->payload['first_name'];
   
            //
        }
    }
    

    'user.created' => [HandleUserCreatedMessage::class, 'handle'],
    

'shipmate' => [
    'driver' => 'shipmate',
    'bucket' => env('STORAGE_BUCKET_NAME'),
    'visibility' => 'public', // public or private
],

$disk = Storage::disk('shipmate');

$disk->put('avatars/1', $fileContents);
$exists = $disk->exists('file.jpg');
$time = $disk->lastModified('file1.jpg');
$disk->copy('old/file1.jpg', 'new/file1.jpg');
$disk->move('old/file1.jpg', 'new/file1.jpg');
$url = $disk->url('folder/my_file.txt');
$url = $disk->temporaryUrl('folder/my_file.txt', now()->addMinutes(30));
$disk->setVisibility('folder/my_file.txt', 'public');
bash
php artisan vendor:publish --tag="shipmate-config"