wip: add interaction schemas
This commit is contained in:
parent
c592f7f371
commit
74bbf5a5c1
13
app/Enums/InteractionType.php
Normal file
13
app/Enums/InteractionType.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use App\Traits\EnumAsArray;
|
||||||
|
|
||||||
|
enum InteractionType: string
|
||||||
|
{
|
||||||
|
use EnumAsArray;
|
||||||
|
|
||||||
|
case Like = 'like';
|
||||||
|
case Favorite = 'favorite';
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
|
||||||
class Deal extends Model
|
class Deal extends Model
|
||||||
{
|
{
|
||||||
@ -16,4 +17,9 @@ public function category(): BelongsTo
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(DealCategory::class, 'deal_category_id');
|
return $this->belongsTo(DealCategory::class, 'deal_category_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function interactions(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->morphMany(Interaction::class, 'interactable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
app/Models/Interaction.php
Normal file
14
app/Models/Interaction.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
|
class Interaction extends Model
|
||||||
|
{
|
||||||
|
public function interactable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\InteractionType;
|
||||||
|
use App\Models\Deal;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('interactions', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignIdFor(User::class);
|
||||||
|
$table->foreignIdFor(Deal::class);
|
||||||
|
$table->enum('type', InteractionType::values());
|
||||||
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('interactions');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user