[Yandex Cloud documentation](../../index.md) > [Yandex Message Queue](../index.md) > [Getting started](index.md) > Code examples > Laravel

# Example of using Yandex Message Queue on Laravel

To work with queues, the [Laravel](https://laravel.com/) PHP framework provides the [Queue](https://laravel.com/docs/6.x/queues) primitive. As a message broker, you can use Message Queue.

## Installation {#install}

Install the Laravel software using the [instructions](https://laravel.com/docs/6.x/installation) on the framework's official website.

## Getting started {#prepare}

1. [Create a service account](../../iam/operations/sa/create.md).
1. [Assign the editor role to the service account](../../iam/operations/sa/assign-role-for-sa.md).
1. [Create a static access key](../../iam/operations/authentication/manage-access-keys.md#create-access-key).

Set the environment variables:

```
export AWS_ACCESS_KEY_ID="<access_key_ID>"
export AWS_SECRET_ACCESS_KEY="<secret_key>"
```

Create a queue in Message Queue and copy the URL.

## Guide {#sample}

In this example, we create a demo job that sums up two numbers and a command that adds the job to a queue in Message Queue.

To use Message Queue with Laravel, follow this guide.

1. Create a test project named `mq_example`:

   ```
   composer create-project --prefer-dist laravel/laravel mq_example
   ```

1. Create an `Add` job:

   ```
   php artisan make:job Add
   ```

1. Open the file `/app/Jobs/Add.php` and reformat it as follows:

   ```php
   <?php

   namespace App\Jobs;

   use Illuminate\Bus\Queueable;
   use Illuminate\Queue\SerializesModels;
   use Illuminate\Queue\InteractsWithQueue;
   use Illuminate\Contracts\Queue\ShouldQueue;
   use Illuminate\Foundation\Bus\Dispatchable;

   class Add implements ShouldQueue
   {
       use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

       private $addend1 = null;
       private $addend2 = null;

       /**
        * Create a new job instance.
        *
        * @return void
        */
       public function __construct($addend1, $addend2)
       {
           $this->addend1 = $addend1;
           $this->addend2 = $addend2;
       }

       /**
        * Execute the job.
        */
       public function handle()
       {
           $result = $this->addend1 + $this->addend2;
           print("{$this->addend1} + {$this->addend2} = $result\n");
       }
   }
   ```

1. Create a new `ScheduleAdd` command:

   ```
   php artisan make:command ScheduleAdd
   ```

1. Open the file `app/Console/Commands/ScheduleAdd.php` and reformat it as follows:

   ```php
   <?php

   namespace App\Console\Commands;

   use App\Jobs\Add;

   use Illuminate\Console\Command;

   class ScheduleAdd extends Command
   {
       /**
        * The name and signature of the console command.
        *
        * @var string
        */
       protected $signature = 'sample:schedule-add';

       /**
        * The console command description.
        *
        * @var string
        */
       protected $description = 'Command description';

       /**
        * Create a new command instance.
        *
        * @return void
        */
       public function __construct()
       {
           parent::__construct();
       }

       /**
        * Execute the console command.
        *
        * @return mixed
        */
       public function handle()
       {
           Add::dispatch(2, 3);
       }
   }
   ```

1. Open the file `config/queue.php` and change the string `'default' = > env ('QUEUE_CONNECTION', 'sync'),` to `'default' => 'sqs',`.

1. Fill in the parameters in the `sqs` section.

   To get values for the `prefix` and `queue` parameters, split the URL of your queue into two parts: the prefix is `https://message-queue.api.cloud.yandex.net/`, while the queue parameter is `b1g8ad42m6he********/dj6000000000********` without the leading `/`.

   ```
   'sqs' => [
       'driver' => 'sqs',
       'key' => env('AWS_ACCESS_KEY_ID'),
       'secret' => env('AWS_SECRET_ACCESS_KEY'),
       'prefix' => env('SQS_PREFIX', 'https://message-queue.api.cloud.yandex.net/'),
       'queue' => env('SQS_QUEUE', 'b1g8ad42m6he********/dj6000000000********/laravel-test'),
       'region' => env('AWS_DEFAULT_REGION', 'ru-central1'),
   ],
   ```

1. Add the `aws/aws-sdk-php` package to the project dependencies:

   ```
   composer require aws/aws-sdk-php
   ```

1. Update the Composer configuration:

   ```
   composer update
   ```

1. Run this command:

   ```
   php artisan sample:schedule-add
   ```

1. Run this command:

   ```
   php artisan queue:work
   ```