Migrations and factories

This commit is contained in:
2020-08-08 20:44:24 +05:00
parent c20392a24c
commit a587a25491
7 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Article;
use App\Source;
use Faker\Generator as Faker;
$factory->define(Article::class, function (Faker $faker) {
return [
'title' => $faker->sentence,
'author' => $faker->name,
'featured_image' => "https://images-01.avas.mv/post/big_pUd28VpL9K3vQJjHbAZDYlaBl.jpg",
"body" => $faker->paragraph,
"source_id" => factory(App\Source::class),
"published_date" => $faker->dateTime,
];
});

View File

@@ -0,0 +1,15 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Source;
use Faker\Generator as Faker;
$factory->define(Source::class, function (Faker $faker) {
return [
"name" => $faker->word,
"slug" => $faker->slug,
"logo" => "https://habaru.mv/assets/sources/Feshun.mv.png",
"url" => $faker->url
];
});

View File

@@ -0,0 +1,13 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Topic;
use Faker\Generator as Faker;
$factory->define(Topic::class, function (Faker $faker) {
return [
"name" => $faker->name,
"slug" => $faker->slug
];
});

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('title');
$table->string('author')->nullable();
$table->string('featured_image');
$table->text('body');
$table->unsignedBigInteger('source_id');
$table->dateTime('published_date');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTopicsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('topics', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('topics');
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSourcesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sources', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug');
$table->string('logo');
$table->string('url');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sources');
}
}

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateArticleTopicTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('article_topic', function (Blueprint $table) {
$table->primary(['article_id', 'topic_id']);
$table->uuid('article_id');
$table->unsignedBigInteger('topic_id');
$table->timestamps();
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
$table->foreign('topic_id')->references('id')->on('topics')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('article_topic');
}
}