generated from ucan-lab/docker-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f68ad38
commit 80d7372
Showing
6 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,8 @@ | |
|
||
class Folder extends Model | ||
{ | ||
// | ||
public function tasks() | ||
{ | ||
return $this->hasMany('App\Task'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Task extends Model | ||
{ | ||
const STATUS = [ | ||
1 => ['label' => '未着手', 'class' => 'label-danger'], | ||
2 => ['label' => '着手中', 'class' => 'label-info'], | ||
3 => ['label' => '完了', 'class' => ''], | ||
]; | ||
|
||
public function getStatusLabelAttribute() | ||
{ | ||
$status = $this->attributes['status']; | ||
|
||
if (!isset(self::STATUS[$status])) { | ||
return ''; | ||
} | ||
|
||
return self::STATUS[$status]['label']; | ||
} | ||
|
||
public function getStatusClassAttribute() | ||
{ | ||
$status = $this->attributes['status']; | ||
|
||
if (!isset(self::STATUS[$status])) { | ||
return ''; | ||
} | ||
|
||
return self::STATUS[$status]['class']; | ||
} | ||
|
||
public function getFormattedDueDateAttribute() | ||
{ | ||
return Carbon::createFromFormat('Y-m-d', $this->attributes['due_date'])->format('Y/m/d'); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
backend/database/migrations/2020_07_23_125033_create_tasks_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateTasksTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('tasks', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->integer('folder_id')->unsigned(); | ||
$table->string('title', 100); | ||
$table->date('due_date'); | ||
$table->integer('status')->default(1); | ||
$table->timestamps(); | ||
|
||
$table->foreign('folder_id')->references('id')->on('folders'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('tasks'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\DB; | ||
use Carbon\Carbon; | ||
|
||
class TasksTableSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
foreach (range(1, 3) as $num) { | ||
DB::table('tasks')->insert([ | ||
'folder_id' => 1, | ||
'title' => "サンプルタスク {$num}", | ||
'status' => $num, | ||
'due_date' => Carbon::now()->addDay($num), | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters