{"id":454456,"date":"2025-04-02T03:02:32","date_gmt":"2025-04-02T03:02:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=454456"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=454456","title":{"rendered":"<span>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Laravel<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! <\/p>\n<p><strong>\u0411\u044b\u0432\u0430\u043b\u043e \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u043e\u0435?<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f MySQL-\u0431\u0430\u0437\u0430 \u0440\u0430\u0437\u0440\u043e\u0441\u043b\u0430\u0441\u044c \u0434\u043e \u0433\u0438\u0433\u0430\u043d\u0442\u0441\u043a\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432, \u0438 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u043e\u0440\u043c\u043e\u0437\u044f\u0442 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0430\u0440\u043e\u0439 \u043b\u0435\u0433\u0430\u0441\u0438-\u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043d\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0411\u0414 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u0440\u043e\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e MongoDB, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u2014 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e PostgreSQL.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0442\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441:\u00a0<strong>\u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/strong><\/p>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p><strong>\u0420\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>\u00a0\u2013 \u0435\u0441\u043b\u0438 \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u0433\u0438, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430) \u043f\u043b\u043e\u0445\u043e \u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<br \/><strong>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043b\u0435\u0433\u0430\u0441\u0438-\u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439<\/strong>\u00a0\u2013 \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0411\u0414 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f, \u043d\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043d\u0443\u0436\u043d\u043e \u0441 \u043d\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<br \/><strong>\u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong>\u00a0\u2013 \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u0438\u043b\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0411\u0414 \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.                                                                                                                                 <strong>\u0418\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>\u00a0\u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u043e\u0439 \u0411\u0414.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Laravel<\/h4>\n<p>Laravel \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443.<\/p>\n<h3>1. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u00a0config\/database.php:<\/p>\n<pre><code class=\"php\">'connections' =&gt; [     'mysql' =&gt; [  \/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430         'driver' =&gt; 'mysql',         'host' =&gt; env('DB_HOST', '127.0.0.1'),         'port' =&gt; env('DB_PORT', '3306'),         'database' =&gt; env('DB_DATABASE', 'forge'),         'username' =&gt; env('DB_USERNAME', 'forge'),         'password' =&gt; env('DB_PASSWORD', ''),         'charset' =&gt; 'utf8mb4',         'collation' =&gt; 'utf8mb4_unicode_ci',     ],      'secondary' =&gt; [  \/\/ \u0412\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u0437\u0430         'driver' =&gt; 'mysql',         'host' =&gt; env('DB_SECONDARY_HOST', '127.0.0.1'),         'port' =&gt; env('DB_SECONDARY_PORT', '3306'),         'database' =&gt; env('DB_SECONDARY_DATABASE', 'forge'),         'username' =&gt; env('DB_SECONDARY_USERNAME', 'forge'),         'password' =&gt; env('DB_SECONDARY_PASSWORD', ''),         'charset' =&gt; 'utf8mb4',         'collation' =&gt; 'utf8mb4_unicode_ci',     ], ],<\/code><\/pre>\n<p>2. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 .env<\/p>\n<pre><code>DB_SECONDARY_HOST=127.0.0.1 DB_SECONDARY_PORT=3306 DB_SECONDARY_DATABASE=secondary_db DB_SECONDARY_USERNAME=root DB_SECONDARY_PASSWORD=secret<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0435\u0441\u044c \u0446\u0438\u043a\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0439 \u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 CRUD \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430.  <\/p>\n<h3>1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437<\/h3>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430 (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438)<\/h4>\n<p><code>php artisan make:migration create_users_table<\/code><\/p>\n<pre><code class=\"php\">Schema::create('users', function (Blueprint $table) {     $table-&gt;id();     $table-&gt;string('name');     $table-&gt;string('email')-&gt;unique();     $table-&gt;string('shard_key')-&gt;comment('\u041a\u043b\u044e\u0447 \u0434\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430');     $table-&gt;timestamps(); });<\/code><\/pre>\n<h4>\u0412\u0442\u043e\u0440\u0438\u0447\u043d\u0430\u044f \u0431\u0430\u0437\u0430 (\u0437\u0430\u043a\u0430\u0437\u044b)<\/h4>\n<p><code>php artisan make:migration create_orders_table<\/code><\/p>\n<pre><code class=\"php\">Schema::connection('secondary')-&gt;create('orders', function (Blueprint $table) {     $table-&gt;id();     $table-&gt;foreignId('user_id');     $table-&gt;decimal('amount', 10, 2);     $table-&gt;string('status');     $table-&gt;timestamps(); });<\/code><\/pre>\n<h3>2. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438<\/h3>\n<h4>\u041c\u043e\u0434\u0435\u043b\u044c User (\u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430)<\/h4>\n<pre><code class=\"php\">class User extends Model {     protected $connection = 'mysql';          public function orders(): HasMany     {         \/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u0437\u0430\u043a\u0430\u0437\u0430\u043c\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0437\u0435. \u0412 \u043c\u043e\u0434\u0435\u043b\u0435 Order \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e        \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c $connection!          return $this-&gt;hasMany(             Order::class,             'user_id',             'id',         );     }          \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0448\u0430\u0440\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f      public function getConnectionName()     {         if ($this-&gt;shard_key !== null) {             return $this-&gt;shard_key % 2 == 0                  ? 'mysql_shard1'                  : 'mysql_shard2';         }                  return parent::getConnectionName();     } }<\/code><\/pre>\n<h4>\u041c\u043e\u0434\u0435\u043b\u044c Order (\u0432\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u0437\u0430)<\/h4>\n<pre><code class=\"php\">class Order extends Model {     protected $connection = 'secondary';          public function user(): BelongsTo     {         \/\/ \u041e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0412 \u043c\u043e\u0434\u0435\u043b\u0435 User \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e        \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c $connection!          return $this-&gt;belongsTo(             User::class,             'user_id',             'id',         );     } }<\/code><\/pre>\n<h3>3. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e CRUD \u0441 \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u043c<\/h3>\n<h4>UserService (\u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438)<\/h4>\n<pre><code class=\"php\">class UserService {     public function createUser(array $data)     {         \/\/ \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0448\u0430\u0440\u0434\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 email         $shardKey = crc32($data['email']) % 2;         $data['shard_key'] = $shardKey;                  return User::create($data);     } }<\/code><\/pre>\n<pre><code class=\"php\">public function getUserWithOrders($userId)     {         $user = User::findOrFail($userId);         $orders = $user-&gt;orders()-&gt;get();                  return [             'user' =&gt; $user,             'orders' =&gt; $orders         ];     }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0438 \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0432 \u043d\u0443\u0436\u043d\u0443\u044e \u043d\u0430\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 Laravel \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0432\u0443\u043c\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>connection()<\/code><\/p>\n<p>\u0421\u0432\u044b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0432\u0443\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043f\u0430\u043a\u0435\u0442\u043e\u043c \u0434\u043b\u044f Laravel \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u041d\u0435\u0440\u0430\u0432\u043d\u043e\u0434\u0443\u0448\u043d\u044b\u0435, \u0441\u043f\u043b\u043e\u0447\u0430\u0435\u043c\u0441\u044f! <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Laravel \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0438\u043b\u0438\u0439, \u043d\u043e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u0427\u0451\u0442\u043a\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435, \u043a\u0430\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u043a\u0430\u043a\u0438\u043c \u0411\u0414 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u044c\u0442\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u0410 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0411\u0414 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/strong>\u00a0\u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u2014 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/896568\/\"> https:\/\/habr.com\/ru\/articles\/896568\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! <\/p>\n<p><strong>\u0411\u044b\u0432\u0430\u043b\u043e \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u043e\u0435?<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f MySQL-\u0431\u0430\u0437\u0430 \u0440\u0430\u0437\u0440\u043e\u0441\u043b\u0430\u0441\u044c \u0434\u043e \u0433\u0438\u0433\u0430\u043d\u0442\u0441\u043a\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432, \u0438 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u043e\u0440\u043c\u043e\u0437\u044f\u0442 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0430\u0440\u043e\u0439 \u043b\u0435\u0433\u0430\u0441\u0438-\u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043d\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0411\u0414 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u0440\u043e\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e MongoDB, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u2014 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e PostgreSQL.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0442\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441:\u00a0<strong>\u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/strong><\/p>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p><strong>\u0420\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>\u00a0\u2013 \u0435\u0441\u043b\u0438 \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u0433\u0438, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430) \u043f\u043b\u043e\u0445\u043e \u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<br \/><strong>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043b\u0435\u0433\u0430\u0441\u0438-\u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439<\/strong>\u00a0\u2013 \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0411\u0414 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f, \u043d\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043d\u0443\u0436\u043d\u043e \u0441 \u043d\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<br \/><strong>\u0413\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong>\u00a0\u2013 \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u0438\u043b\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0411\u0414 \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.                                                                                                                                 <strong>\u0418\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>\u00a0\u2013 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u043e\u0439 \u0411\u0414.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Laravel<\/h4>\n<p>Laravel \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443.<\/p>\n<h3>1. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u00a0config\/database.php:<\/p>\n<pre><code class=\"php\">'connections' =&gt; [     'mysql' =&gt; [  \/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430         'driver' =&gt; 'mysql',         'host' =&gt; env('DB_HOST', '127.0.0.1'),         'port' =&gt; env('DB_PORT', '3306'),         'database' =&gt; env('DB_DATABASE', 'forge'),         'username' =&gt; env('DB_USERNAME', 'forge'),         'password' =&gt; env('DB_PASSWORD', ''),         'charset' =&gt; 'utf8mb4',         'collation' =&gt; 'utf8mb4_unicode_ci',     ],      'secondary' =&gt; [  \/\/ \u0412\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u0437\u0430         'driver' =&gt; 'mysql',         'host' =&gt; env('DB_SECONDARY_HOST', '127.0.0.1'),         'port' =&gt; env('DB_SECONDARY_PORT', '3306'),         'database' =&gt; env('DB_SECONDARY_DATABASE', 'forge'),         'username' =&gt; env('DB_SECONDARY_USERNAME', 'forge'),         'password' =&gt; env('DB_SECONDARY_PASSWORD', ''),         'charset' =&gt; 'utf8mb4',         'collation' =&gt; 'utf8mb4_unicode_ci',     ], ],<\/code><\/pre>\n<p>2. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 .env<\/p>\n<pre><code>DB_SECONDARY_HOST=127.0.0.1 DB_SECONDARY_PORT=3306 DB_SECONDARY_DATABASE=secondary_db DB_SECONDARY_USERNAME=root DB_SECONDARY_PASSWORD=secret<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0435\u0441\u044c \u0446\u0438\u043a\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0439 \u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 CRUD \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430.  <\/p>\n<h3>1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437<\/h3>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430 (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438)<\/h4>\n<p><code>php artisan make:migration create_users_table<\/code><\/p>\n<pre><code class=\"php\">Schema::create('users', function (Blueprint $table) {     $table-&gt;id();     $table-&gt;string('name');     $table-&gt;string('email')-&gt;unique();     $table-&gt;string('shard_key')-&gt;comment('\u041a\u043b\u044e\u0447 \u0434\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430');     $table-&gt;timestamps(); });<\/code><\/pre>\n<h4>\u0412\u0442\u043e\u0440\u0438\u0447\u043d\u0430\u044f \u0431\u0430\u0437\u0430 (\u0437\u0430\u043a\u0430\u0437\u044b)<\/h4>\n<p><code>php artisan make:migration create_orders_table<\/code><\/p>\n<pre><code class=\"php\">Schema::connection('secondary')-&gt;create('orders', function (Blueprint $table) {     $table-&gt;id();     $table-&gt;foreignId('user_id');     $table-&gt;decimal('amount', 10, 2);     $table-&gt;string('status');     $table-&gt;timestamps(); });<\/code><\/pre>\n<h3>2. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438<\/h3>\n<h4>\u041c\u043e\u0434\u0435\u043b\u044c User (\u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0431\u0430\u0437\u0430)<\/h4>\n<pre><code class=\"php\">class User extends Model {     protected $connection = 'mysql';          public function orders(): HasMany     {         \/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u0437\u0430\u043a\u0430\u0437\u0430\u043c\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0437\u0435. \u0412 \u043c\u043e\u0434\u0435\u043b\u0435 Order \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e        \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c $connection!          return $this-&gt;hasMany(             Order::class,             'user_id',             'id',         );     }          \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0448\u0430\u0440\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f      public function getConnectionName()     {         if ($this-&gt;shard_key !== null) {             return $this-&gt;shard_key % 2 == 0                  ? 'mysql_shard1'                  : 'mysql_shard2';         }                  return parent::getConnectionName();     } }<\/code><\/pre>\n<h4>\u041c\u043e\u0434\u0435\u043b\u044c Order (\u0432\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u0437\u0430)<\/h4>\n<pre><code class=\"php\">class Order extends Model {     protected $connection = 'secondary';          public function user(): BelongsTo     {         \/\/ \u041e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0412 \u043c\u043e\u0434\u0435\u043b\u0435 User \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e        \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c $connection!          return $this-&gt;belongsTo(             User::class,             'user_id',             'id',         );     } }<\/code><\/pre>\n<h3>3. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e CRUD \u0441 \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u043c<\/h3>\n<h4>UserService (\u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438)<\/h4>\n<pre><code class=\"php\">class UserService {     public function createUser(array $data)     {         \/\/ \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0448\u0430\u0440\u0434\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 email         $shardKey = crc32($data['email']) % 2;         $data['shard_key'] = $shardKey;                  return User::create($data);     } }<\/code><\/pre>\n<pre><code class=\"php\">public function getUserWithOrders($userId)     {         $user = User::findOrFail($userId);         $orders = $user-&gt;orders()-&gt;get();                  return [             'user' =&gt; $user,             'orders' =&gt; $orders         ];     }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0438 \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0432 \u043d\u0443\u0436\u043d\u0443\u044e \u043d\u0430\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 Laravel \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0432\u0443\u043c\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>connection()<\/code><\/p>\n<p>\u0421\u0432\u044b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0432\u0443\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043f\u0430\u043a\u0435\u0442\u043e\u043c \u0434\u043b\u044f Laravel \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u041d\u0435\u0440\u0430\u0432\u043d\u043e\u0434\u0443\u0448\u043d\u044b\u0435, \u0441\u043f\u043b\u043e\u0447\u0430\u0435\u043c\u0441\u044f! <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Laravel \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0438\u043b\u0438\u0439, \u043d\u043e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u0427\u0451\u0442\u043a\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435, \u043a\u0430\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u043a\u0430\u043a\u0438\u043c \u0411\u0414 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u044c\u0442\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u0410 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0411\u0414 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/strong>\u00a0\u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u2014 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/896568\/\"> https:\/\/habr.com\/ru\/articles\/896568\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-454456","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=454456"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454456\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=454456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=454456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=454456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}