book cases added

This commit is contained in:
Benjamin Takats
2022-12-07 14:57:15 +01:00
parent e5b4666d4e
commit ce8f87db6f
59 changed files with 2175 additions and 142 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\BookCase;
use App\Models\OrangePill;
use App\Models\User;
class OrangePillFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = OrangePill::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition(): array
{
return [
'user_id' => User::factory(),
'book_case_id' => BookCase::factory(),
'date' => $this->faker->dateTime(),
'amount' => $this->faker->randomNumber(),
];
}
}

View File

@@ -14,6 +14,10 @@ class CreateBookCasesTable extends Migration
{
Schema::create('book_cases', function (Blueprint $table) {
$table->id();
$table->boolean('orange_pilled')
->default(false);
$table->unsignedInteger('orange_pilled_amount')
->default(0);
$table->string('title');
$table->double('lat');
$table->double('lon');

View File

@@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrangePillsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::disableForeignKeyConstraints();
Schema::create('orange_pills', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
$table->foreignId('book_case_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
$table->dateTime('date');
$table->unsignedInteger('amount');
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::dropIfExists('orange_pills');
}
}

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$this->nullableMorphs($table, 'commentator', 'commentator_comments');
$table->morphs('commentable');
$table->foreignId('parent_id')->nullable()->constrained('comments')->onDelete('cascade');
$table->longText('original_text');
$table->longText('text');
$table->json('extra')->nullable();
$table->timestamp('approved_at')->nullable();
$table->timestamps();
});
Schema::create('reactions', function (Blueprint $table) {
$table->id();
$this->nullableMorphs($table, 'commentator', 'commentator_reactions');
$table->foreignId('comment_id')->references('id')->on('comments')->cascadeOnDelete();
$table->string('reaction')->collation('C.UTF-8');
$table->timestamps();
});
Schema::create('comment_notification_subscriptions', function(Blueprint $table) {
$table->id();
$table->morphs('commentable', 'cn_subscriptions_commentable');
$table->morphs('subscriber', 'cn_subscriptions_subscriber');
$table->string('type');
$table->timestamps();
});
}
protected function nullableMorphs(Blueprint $table, string $name, string $indexName): void
{
$table->string("{$name}_type")->nullable();
$table->unsignedBigInteger("{$name}_id")->nullable();
$table->index(["{$name}_type", "{$name}_id"], $indexName);
}
};