Todo model and migration

This commit is contained in:
Supan Adit Pratama 2020-06-24 00:45:04 +07:00
parent e5dd77e1d7
commit bf08bdc026
6 changed files with 111 additions and 3 deletions

View File

@ -10,4 +10,9 @@ class TodoController extends Controller
{
return view('home');
}
public function createTodo()
{
}
}

13
app/Todo.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Todo extends Model
{
public function todoItems()
{
return $this->hasMany('App\TodoItem');
}
}

13
app/TodoItem.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class TodoItem extends Model
{
public function todo()
{
return $this->hasOne('App\Todo');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTodosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('todos', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string("name");
$table->text("Description");
$table->unsignedBigInteger('user_id')->default(false);
});
Schema::table('todos', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('todos');
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTodoItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('todo_items', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->unsignedBigInteger('todo_id');
$table->string('name');
$table->boolean('complete')->default(false);
});
Schema::table('todo_items', function (Blueprint $table) {
$table->foreign('todo_id')->references('id')->on('todos');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('todo_items');
}
}

View File

@ -10,7 +10,7 @@
@section('top-button')
<button class="btn btn-info btn-sm" data-toggle="modal" data-target="#modal-default">
Create Todo
Create Directory
</button>
@endsection
@ -76,8 +76,8 @@
return false;
}
// CTRL + N
if (e.shiftKey && e.which === 78) {
// ALT + N
if (e.altKey && e.which === 78) {
$("#modal-default").modal('show');
return false;
}