Skip to content

Commit

Permalink
feat: task model
Browse files Browse the repository at this point in the history
  • Loading branch information
hekmatinasser committed Feb 22, 2024
1 parent 8d2158a commit bb36d19
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;

/**
* @property int $user_id
* @property string $title
* @property string $description
* @property Carbon $completed_at
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class Task extends Model
{
use HasFactory;

protected $fillable = [
'user_id',
'title',
'description',
'completed_at',
];

protected $casts = [
'completed_at' => 'datetime'
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
31 changes: 31 additions & 0 deletions database/migrations/2024_02_22_210501_create_tasks_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

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('tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users');
$table->string('title');
$table->string('description')->nullable();
$table->timestamp('completed_at')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tasks');
}
};

0 comments on commit bb36d19

Please sign in to comment.