Migrations and factories
This commit is contained in:
18
database/factories/ArticleFactory.php
Normal file
18
database/factories/ArticleFactory.php
Normal 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,
|
||||
];
|
||||
});
|
||||
15
database/factories/SourceFactory.php
Normal file
15
database/factories/SourceFactory.php
Normal 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
|
||||
];
|
||||
});
|
||||
13
database/factories/TopicFactory.php
Normal file
13
database/factories/TopicFactory.php
Normal 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
|
||||
];
|
||||
});
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user