2025-03-06 10:14:48 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-03-06 19:57:42 +09:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2025-03-06 10:14:48 +09:00
|
|
|
|
|
|
|
|
class Task extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2025-03-06 17:00:09 +09:00
|
|
|
|
2025-03-06 21:46:32 +09:00
|
|
|
protected static function boot()
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
|
static::creating(function ($task) {
|
|
|
|
|
if (is_null($task->completed)) {
|
|
|
|
|
$task->completed = false; // Ensure completed is false when creating a new task
|
|
|
|
|
}
|
2025-03-06 22:25:46 +09:00
|
|
|
$task->user_id = Auth::id(); // Set user_id automatically
|
2025-03-06 21:46:32 +09:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* protected $attributes = [
|
2025-03-06 17:00:09 +09:00
|
|
|
'completed' => false, // Set default value for completed
|
2025-03-06 21:46:32 +09:00
|
|
|
]; */
|
2025-03-06 17:00:09 +09:00
|
|
|
|
2025-03-06 19:57:42 +09:00
|
|
|
|
2025-03-06 17:00:09 +09:00
|
|
|
public function user() {
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
public function category() {
|
|
|
|
|
return $this->belongsTo(Category::class);
|
|
|
|
|
}
|
2025-03-06 10:14:48 +09:00
|
|
|
}
|