{"id":327844,"date":"2022-01-11T15:00:36","date_gmt":"2022-01-11T15:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327844"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327844","title":{"rendered":"<span>Laravel: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a \u0438 seeders \u043f\u0440\u0438 \u0441\u0432\u044f\u0437\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0430\u0442\u044c\u044f \u0438 \u0435\u0435 \u0430\u0432\u0442\u043e\u0440, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0438 \u0438 \u0442.\u043f.), \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a (Factory) \u0438 \u0441\u0438\u0434\u043e\u0432 (Seeders) \u043a \u044d\u0442\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044f\u043c. <\/p>\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0431\u0440\u0438\u043a \u0438 \u0441\u0438\u0434\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0421\u043f\u043e\u0439\u043b\u0435\u0440: \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u0438\u0434\u043e\u0432.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u0433\u0434\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u0435\u0435 \u0430\u0432\u0442\u043e\u0440. \u0410\u0432\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0430\u0439\u0442\u0430, \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u0438\u0434\u0435\u0440\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a \u043d\u0435\u043c\u0443.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 (\u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/mvsvolkov\/laravel_relation_factories\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/u><\/a>). \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e, \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0438 \u0441\u0438\u0434 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0435\u0439. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430 \u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0447\u0442\u043e \u0438\u0434\u0435\u0442 \u0432 Laravel \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Laravel, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a, \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code>laravel new relation_factories<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0444\u0430\u0439\u043b .env, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0411\u0414, \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0411\u0414 sqlite.<\/p>\n<pre><code>\/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0430\u0439\u043b\u0430 .env  DB_CONNECTION=sqlite DB_DATABASE=\/path...to...project\/database\/database.sqlite<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0411\u0414 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<pre><code>touch database\/database.sqlite<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438<\/h2>\n<p>\u041f\u043e\u043a\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043d\u0435\u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan make:model -f -m Article<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u0441\u0442\u0430\u0442\u044c\u0438. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.  <\/p>\n<pre><code>&lt;?php  use Illuminate\\Database\\Migrations\\Migration; use Illuminate\\Database\\Schema\\Blueprint; use Illuminate\\Support\\Facades\\Schema;  class CreateArticlesTable extends Migration {    public function up()    {        Schema::create('articles', function (Blueprint $table) {            $table->id();            $table->string('title');            $table->foreignId('author_id')                ->references('id')                ->on('users')                ->cascadeOnDelete()            ;            $table->timestamps();        });    }     public function down()    {        Schema::dropIfExists('articles');    } }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.\u00a0<\/p>\n<pre><code>&lt;?php  namespace App\\Models;  use Illuminate\\Database\\Eloquent\\Factories\\HasFactory; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Database\\Eloquent\\Relations\\BelongsTo;  class Article extends Model {    use HasFactory;     public function author(): BelongsTo    {        return $this->belongsTo(User::class, 'author_id');    } }<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan migrate<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0441\u0438\u0434\u043e\u0432<\/h2>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0441\u0438\u0434\u0430. <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438. \u0423 \u0441\u0442\u0430\u0442\u044c\u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u2014 \u044d\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.<\/p>\n<pre><code>&lt;?php  namespace Database\\Factories;  use App\\Models\\Article; use App\\Models\\User; use Illuminate\\Database\\Eloquent\\Factories\\Factory;  class ArticleFactory extends Factory {    protected $model = Article::class;     public function definition(): array    {        return [            'title' => $this->faker->sentence,        ];    } }<\/code><\/pre>\n<p>\u041e\u043f\u044b\u0442\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0437\u0434\u0435\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043c\u044b \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0435\u0439 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435, \u0430 \u043f\u043e\u043a\u0430 \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0441\u0438\u0434\u0430. \u0411\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <em>DatabaseSeeder<\/em>, \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0434\u043e\u0432.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c, \u043a\u0430\u043a \u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u0438\u0435, \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u0435\u0439.<\/p>\n<pre><code>&lt;?php  namespace Database\\Seeders;  use App\\Models\\Article; use App\\Models\\User; use Illuminate\\Database\\Seeder;  class DatabaseSeeder extends Seeder {     public function run()    {         User::factory()->create();         Article::factory()->count(5)->create();    } }<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0438\u0434\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.  <\/p>\n<pre><code>php artisan db:seed<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443.  <\/p>\n<pre><code>Illuminate\\Database\\QueryException   SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: articles.author_id ...<\/code><\/pre>\n<h2>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u21161  <\/h2>\n<p>\u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c. \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0438\u0434\u0430 \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 ? \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0432 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 1 \u0432 \u043f\u043e\u043b\u0435.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => 1,        ];    } }<\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442, \u043d\u043e \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u044d\u0442\u0430 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0430\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u0430? \u042f \u0442\u043e\u0436\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e. \u0422\u0430\u043a \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0411\u0414 \u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0435\u0433\u043e id.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::first()->id,        ];    } }<\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0436\u0435\u0441\u0442\u043a\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0411\u0414 \u0438 \u0435\u0433\u043e id, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0441\u043a\u0440\u0438\u043d\u0435 \u043d\u0438\u0436\u0435<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::all()->random()->id,        ];    } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0438 \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0439. \u0412 \u0411\u0414 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0417\u0430\u0447\u0435\u043c \u0442\u044f\u043d\u0443\u0442\u044c \u0438\u0445 \u0432\u0441\u0435\u0445, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c php \u0438 \u043f\u043e\u0442\u043e\u043c \u0441\u0438\u043b\u0430\u043c\u0438 php \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c? \u041d\u0443\u0436\u043d\u043e \u0443\u0436\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414, \u0432\u0437\u044f\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0438.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::inRandomOrder()->first()->id,        ];    } }<\/code><\/pre>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0414\u0430\u043b\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044e, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0410 \u043f\u043e\u043a\u0430 \u0441\u0431\u0440\u043e\u0441\u0438\u043c \u0432\u0441\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0438\u0445 \u0441\u043d\u043e\u0432\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u0438\u0434\u0430\u043c\u0438.  <\/p>\n<pre><code>php artisan migrate:fresh --seed<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0447\u0435\u043c\u0443 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0442\u0435\u0441\u0442\u0430 \u043a \u043d\u0435\u0439  <\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0438\u043c\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 callback \u0444\u0443\u043d\u043a\u0446\u0438\u0438.\u00a0<\/p>\n<p>\u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b <em>web.php<\/em><\/p>\n<pre><code>&lt;?php  use App\\Models\\Article; use Illuminate\\Support\\Facades\\Route;  Route::get('\/', function () {    $articles = Article::with('author')->get();    return view('welcome', compact('articles')); })->name('home');<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b <em>welcome.blade.php. <\/em>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c.<\/p>\n<pre><code>@foreach ($articles as $article)    &lt;div>{{ $article->title }} - {{ $article->author->name }}&lt;\/div> @endforeach<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c Laravel \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code>php artisan serve<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 \u0441\u0430\u0439\u0442 \u0438 \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430 \u043d\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.  <\/p>\n<pre><code>Modi eum aliquam beatae ab ut commodi dignissimos est. - Karley Nicolas Quia nostrum id quos et inventore tenetur. - Karley Nicolas Perferendis earum ipsam ex rerum nihil dicta. - Karley Nicolas Amet eos rem adipisci dolorem. - Karley Nicolas Enim debitis itaque et illo occaecati non. - Karley Nicolas<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442<\/h2>\n<p>\u041d\u0438\u0447\u0442\u043e \u0442\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0435 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan make:test ArticlesTest<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442. \u0414\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0435\u0441\u0442\u0430 \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u0439 \u0411\u0414, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0440\u0435\u0439\u0442 <em>RefreshDatabase.<\/em><\/p>\n<pre><code>&lt;?php  namespace Tests\\Feature;  use App\\Models\\Article; use Illuminate\\Foundation\\Testing\\RefreshDatabase; use Illuminate\\Foundation\\Testing\\WithFaker; use Tests\\TestCase;  class ArticlesTest extends TestCase {    use RefreshDatabase;     public function test_main_page_has_articles()    {        \/**         * \u0415\u0441\u043b\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044f         *\/        $article = Article::factory()            ->create(['title' => 'example'])        ;         \/**         * \u0422\u043e, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443         *\/        $response = $this->get(route('home'));         \/**         * \u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0414\u041e\u041b\u0416\u041d\u0410 \u043e\u0442\u043a\u0440\u044b\u0442\u044c\u0441\u044f,         * \u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0414\u041e\u041b\u0416\u0415\u041d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438         *\/        $response            ->assertStatus(200)            ->assertSee($article->title)        ;    } }<\/code><\/pre>\n<p>\u0412 Laravel \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.  <\/p>\n<pre><code>php .\/vendor\/bin\/phpunit<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b. \u041e\u043d \u0432\u044b\u0432\u0435\u043b \u043e\u0448\u0438\u0431\u043a\u0443  <\/p>\n<pre><code>1) Tests\\Feature\\ArticlesTest::test_main_page_has_articles ErrorException: Attempt to read property \"id\" on null<\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 Laravel \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0442\u0430\u043a-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435.<\/p>\n<h2>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u21162  <\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c. \u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0447\u0438\u0441\u0442\u0443\u044e \u0411\u0414 \u043d\u0430\u043a\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u043d\u043e \u0441\u0438\u0434\u0435\u0440\u044b \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0411\u0414 \u043d\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 <em>null<\/em>.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0435\u0441\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u042d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0430\u0442\u044c\u0438. \u0422\u043e\u0433\u0434\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043b\u044f \u043d\u0435\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>\u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u041a\u0441\u0442\u0430\u0442\u0438, \u043f\u043e\u043b\u0435 id \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, Laravel \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u043d\u044b\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u0437\u044f\u0442\u044c id \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430 \u0432\u0430\u0441.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/    public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::factory()->create(),        ];    } }<\/code><\/pre>\n<p>\u0421\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php .\/vendor\/bin\/phpunit<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442 \u043f\u0440\u043e\u0448\u0435\u043b, \u043d\u043e \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430, \u0434\u0430\u0436\u0435 \u0434\u0432\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0432\u0441\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u0438\u0434\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/p>\n<pre><code>php artisan migrate:fresh --seed<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u043c \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code>Ad id sit distinctio perspiciatis accusantium numquam rerum quia. - Isai Rohan Fugit ipsum odio iure. - Gretchen Prosacco Qui est quae asperiores sed. - Abby Leannon Placeat nobis est sed aperiam. - Dahlia McKenzie Quod iste unde assumenda molestias eaque quia dignissimos earum. - Dr. Alysha Gutkowski Jr.<\/code><\/pre>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434 \u0441\u0438\u0434\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0443 create.<\/p>\n<pre><code>&lt;?php  \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class DatabaseSeeder extends Seeder {    public function run()    {         $user = User::factory()->create();         Article::factory()            ->count(5)            ->create(['author_id' => $user])        ;    } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u0438\u0434\u044b. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0432\u0441\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f, \u0442\u0435\u0441\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f.<\/p>\n<p>&#171;\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u0434\u043e&#187; &#8212; \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438 \u0432\u044b. \u041d\u043e \u043d\u0435 \u0442\u0443\u0442-\u0442\u043e \u0431\u044b\u043b\u043e, \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430.<\/p>\n<h2>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u21163<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 <em>create()<\/em> \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0 \u0441\u0432\u044f\u0437\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u043d\u0430\u0441 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432 \u0411\u0414 \u043d\u0435 \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043a\u0430\u043a \u043c\u044b \u0434\u0443\u043c\u0430\u0435\u043c, \u0430 \u0448\u0435\u0441\u0442\u044c. \u041e\u0434\u043d\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0434\u0435\u0440, \u0435\u0449\u0435 \u043f\u044f\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0438\u043d\u043a\u0435\u0440\u0430, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0411\u0414.<\/p>\n<pre><code>php artisan tinker  Psy Shell v0.10.8 (PHP 8.0.10 -- cli) by Justin Hileman >>> App\\Models\\User::count() => 6<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u0430 create \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 make, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0441\u043d\u043e\u0432\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044b\u0439 \u043a\u0440\u0443\u0433.<\/p>\n<h2>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435  <\/h2>\n<p>\u0412\u0435\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435. \u0412\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <em>make()<\/em> \u0438\u043b\u0438 <em>create().<\/em>  <\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::factory(),        ];    } }<\/code><\/pre>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u0422\u0435\u0441\u0442\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0430 \u0441\u0438\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>Laravel \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043c\u0435\u043d, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e \u0432 \u043f\u043e\u043b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0438, \u043e\u0442\u043b\u043e\u0436\u0438\u0442 \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0415\u0441\u043b\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <em>create() <\/em>\u0438\u043b\u0438<em> make()<\/em> \u043f\u043e\u043b\u0435 <em>author_id<\/em> \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435, \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c Laravel \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0441\u0432\u044f\u0437\u0435\u0439.<\/p>\n<p>\u0421 \u0432\u0430\u043c\u0438 \u0431\u044b\u043b \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c QSOFT \u0410\u043a\u0430\u0434\u0435\u043c\u0438\u0438 \u043f\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u201c\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u201d &#8212; <a href=\"https:\/\/mvsvolkov.ru\" rel=\"noopener noreferrer nofollow\"><u>\u0412\u043e\u043b\u043a\u043e\u0432 \u041c\u0438\u0445\u0430\u0438\u043b<\/u><\/a> (<a href=\"https:\/\/habr.com\/ru\/users\/mvsvolkov\/\" rel=\"noopener noreferrer nofollow\">@mvsvolkov<\/a>), \u0432\u0441\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0445 \u0444\u0430\u0431\u0440\u0438\u043a, \u0432\u043a\u0443\u0441\u043d\u044b\u0445 \u0441\u0438\u0434\u043e\u0432 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a. <\/p>\n<\/div>\n<\/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\/post\/645055\/\"> https:\/\/habr.com\/ru\/post\/645055\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0430\u0442\u044c\u044f \u0438 \u0435\u0435 \u0430\u0432\u0442\u043e\u0440, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0438 \u0438 \u0442.\u043f.), \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a (Factory) \u0438 \u0441\u0438\u0434\u043e\u0432 (Seeders) \u043a \u044d\u0442\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044f\u043c. <\/p>\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0431\u0440\u0438\u043a \u0438 \u0441\u0438\u0434\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0421\u043f\u043e\u0439\u043b\u0435\u0440: \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u0438\u0434\u043e\u0432.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u0433\u0434\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u0435\u0435 \u0430\u0432\u0442\u043e\u0440. \u0410\u0432\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0430\u0439\u0442\u0430, \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u0438\u0434\u0435\u0440\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a \u043d\u0435\u043c\u0443.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 (\u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/mvsvolkov\/laravel_relation_factories\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/u><\/a>). \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e, \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0438 \u0441\u0438\u0434 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0435\u0439. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430 \u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0447\u0442\u043e \u0438\u0434\u0435\u0442 \u0432 Laravel \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Laravel, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a, \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code>laravel new relation_factories<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0444\u0430\u0439\u043b .env, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0411\u0414, \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0411\u0414 sqlite.<\/p>\n<pre><code>\/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0430\u0439\u043b\u0430 .env  DB_CONNECTION=sqlite DB_DATABASE=\/path...to...project\/database\/database.sqlite<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0411\u0414 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<pre><code>touch database\/database.sqlite<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438<\/h2>\n<p>\u041f\u043e\u043a\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043d\u0435\u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan make:model -f -m Article<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u0441\u0442\u0430\u0442\u044c\u0438. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.  <\/p>\n<pre><code>&lt;?php  use Illuminate\\Database\\Migrations\\Migration; use Illuminate\\Database\\Schema\\Blueprint; use Illuminate\\Support\\Facades\\Schema;  class CreateArticlesTable extends Migration {    public function up()    {        Schema::create('articles', function (Blueprint $table) {            $table->id();            $table->string('title');            $table->foreignId('author_id')                ->references('id')                ->on('users')                ->cascadeOnDelete()            ;            $table->timestamps();        });    }     public function down()    {        Schema::dropIfExists('articles');    } }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.\u00a0<\/p>\n<pre><code>&lt;?php  namespace App\\Models;  use Illuminate\\Database\\Eloquent\\Factories\\HasFactory; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Database\\Eloquent\\Relations\\BelongsTo;  class Article extends Model {    use HasFactory;     public function author(): BelongsTo    {        return $this->belongsTo(User::class, 'author_id');    } }<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan migrate<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0441\u0438\u0434\u043e\u0432<\/h2>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0441\u0438\u0434\u0430. <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438. \u0423 \u0441\u0442\u0430\u0442\u044c\u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u2014 \u044d\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.<\/p>\n<pre><code>&lt;?php  namespace Database\\Factories;  use App\\Models\\Article; use App\\Models\\User; use Illuminate\\Database\\Eloquent\\Factories\\Factory;  class ArticleFactory extends Factory {    protected $model = Article::class;     public function definition(): array    {        return [            'title' => $this->faker->sentence,        ];    } }<\/code><\/pre>\n<p>\u041e\u043f\u044b\u0442\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0437\u0434\u0435\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043c\u044b \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0435\u0439 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435, \u0430 \u043f\u043e\u043a\u0430 \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0441\u0438\u0434\u0430. \u0411\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <em>DatabaseSeeder<\/em>, \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0434\u043e\u0432.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c, \u043a\u0430\u043a \u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u0438\u0435, \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u0435\u0439.<\/p>\n<pre><code>&lt;?php  namespace Database\\Seeders;  use App\\Models\\Article; use App\\Models\\User; use Illuminate\\Database\\Seeder;  class DatabaseSeeder extends Seeder {     public function run()    {         User::factory()->create();         Article::factory()->count(5)->create();    } }<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0438\u0434\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.  <\/p>\n<pre><code>php artisan db:seed<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443.  <\/p>\n<pre><code>Illuminate\\Database\\QueryException   SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: articles.author_id ...<\/code><\/pre>\n<h2>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u21161  <\/h2>\n<p>\u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c. \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0438\u0434\u0430 \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 ? \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0432 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 1 \u0432 \u043f\u043e\u043b\u0435.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => 1,        ];    } }<\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442, \u043d\u043e \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u044d\u0442\u0430 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0430\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u0430? \u042f \u0442\u043e\u0436\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e. \u0422\u0430\u043a \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0411\u0414 \u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0435\u0433\u043e id.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::first()->id,        ];    } }<\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0436\u0435\u0441\u0442\u043a\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0411\u0414 \u0438 \u0435\u0433\u043e id, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0441\u043a\u0440\u0438\u043d\u0435 \u043d\u0438\u0436\u0435<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::all()->random()->id,        ];    } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0438 \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0439. \u0412 \u0411\u0414 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0417\u0430\u0447\u0435\u043c \u0442\u044f\u043d\u0443\u0442\u044c \u0438\u0445 \u0432\u0441\u0435\u0445, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c php \u0438 \u043f\u043e\u0442\u043e\u043c \u0441\u0438\u043b\u0430\u043c\u0438 php \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c? \u041d\u0443\u0436\u043d\u043e \u0443\u0436\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414, \u0432\u0437\u044f\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0438.<\/p>\n<pre><code>&lt;?php \/* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 *\/  class ArticleFactory extends Factory {    \/* \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 *\/     public function definition(): array    {        return [            'title' => $this->faker->sentence,            'author_id' => User::inRandomOrder()->first()->id,        ];    } }<\/code><\/pre>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0414\u0430\u043b\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044e, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0410 \u043f\u043e\u043a\u0430 \u0441\u0431\u0440\u043e\u0441\u0438\u043c \u0432\u0441\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0438\u0445 \u0441\u043d\u043e\u0432\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u0438\u0434\u0430\u043c\u0438.  <\/p>\n<pre><code>php artisan migrate:fresh --seed<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0447\u0435\u043c\u0443 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0442\u0435\u0441\u0442\u0430 \u043a \u043d\u0435\u0439  <\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0438\u043c\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 callback \u0444\u0443\u043d\u043a\u0446\u0438\u0438.\u00a0<\/p>\n<p>\u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b <em>web.php<\/em><\/p>\n<pre><code>&lt;?php  use App\\Models\\Article; use Illuminate\\Support\\Facades\\Route;  Route::get('\/', function () {    $articles = Article::with('author')->get();    return view('welcome', compact('articles')); })->name('home');<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b <em>welcome.blade.php. <\/em>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c.<\/p>\n<pre><code>@foreach ($articles as $article)    &lt;div>{{ $article->title }} - {{ $article->author->name }}&lt;\/div> @endforeach<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c Laravel \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code>php artisan serve<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 \u0441\u0430\u0439\u0442 \u0438 \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430 \u043d\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.  <\/p>\n<pre><code>Modi eum aliquam beatae ab ut commodi dignissimos est. - Karley Nicolas Quia nostrum id quos et inventore tenetur. - Karley Nicolas Perferendis earum ipsam ex rerum nihil dicta. - Karley Nicolas Amet eos rem adipisci dolorem. - Karley Nicolas Enim debitis itaque et illo occaecati non. - Karley Nicolas<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442<\/h2>\n<p>\u041d\u0438\u0447\u0442\u043e \u0442\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0435 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code>php artisan make:test ArticlesTest<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442. \u0414\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0435\u0441\u0442\u0430 \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u0439 \u0411\u0414, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0440\u0435\u0439\u0442 <em>RefreshDatabase.<\/em><\/p>\n<pre><code>&lt;?php  namespace Tests\\Feature;  use App\\Models\\Article; use Illuminate\\Foundation\\Testing\\RefreshDatabase; use Illuminate\\Foundation\\Testing\\WithFaker; use Tests\\TestCase;  class ArticlesTest extends TestCase {    use RefreshDatabase;     public function test_main_page_has_articles()    {        \/**         * \u0415\u0441\u043b\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044f         *\/        $article = Article::factory()            ->create(['title' => 'example'])        ;         \/**         * \u0422\u043e, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443         *\/        $response = $this->get(route('home'));         \/**         * \u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0414\u041e\u041b\u0416\u041d\u0410 \u043e\u0442\u043a\u0440\u044b\u0442\u044c\u0441\u044f,         * \u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0414\u041e\u041b\u0416\u0415\u041d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438         *\/        $response            ->assertStatus(200)            ->assertSee($article->title)        ;    } }<\/code><\/pre>\n<p>\u0412 Laravel \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.  <\/p>\n<pre><code>php .\/vendor\/bin\/phpunit<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b. \u041e\u043d \u0432\u044b\u0432\u0435\u043b \u043e\u0448\u0438\u0431\u043a\u0443  <\/p>\n<pre><code>1) Tests\\Feature\\ArticlesTest::test_main_page_has_articles ErrorException: Attempt to read property \"id\" on null<\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 Laravel \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0442\u0430\u043a-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435.<\/p>\n<h2>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u21162  <\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c. \u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0447\u0438\u0441\u0442\u0443\u044e \u0411\u0414<\/p>\n<\/div>\n<\/div>\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-327844","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327844","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=327844"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327844\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}