Last active
November 11, 2016 04:27
-
-
Save sshono1210/e42663e1b7312047132e588cf5cd7408 to your computer and use it in GitHub Desktop.
Laravel 5.3 - Basic Task List
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
public function up() { | |
Schema::create(‘tasks’, function(Blueprint $table){ | |
$table->increments(‘id’); | |
$table->string(‘name’); // 追加 | |
$table->timestamps(); | |
}); | |
} |
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
$task = new Task; | |
$task->name = $request->get(‘name’); | |
$task->save(); | |
return redirect('/'); |
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
@extends('layouts.app') | |
@section('content') | |
<div class="container"> | |
<div class="panel-body"> | |
<!-- Display Validation Errors --> | |
@include('common.errors') | |
<!-- New Task Form --> | |
<form action="{{ url('task') }}" method="POST" class="form-horizontal"> | |
{{ csrf_field() }} | |
<!-- Task Name --> | |
<div class="form-group"> | |
<label for="task" class="col-sm-3 control-label">Task</label> | |
<div class="col-sm-6"> | |
<input type="text" name="name" id="task-name" class="form-control"> | |
</div> | |
</div> | |
<!-- Add Task Button --> | |
<div class="form-group"> | |
<div class="col-sm-offset-3 col-sm-6"> | |
<button type="submit" class="btn btn-default"> | |
<i class="fa fa-plus"></i> Add Task | |
</button> | |
</div> | |
</div> | |
</form> | |
</div> | |
<!-- TODO: Current Tasks --> | |
</div> | |
@endsection |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Laravel Quickstart - Basic</title> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,700" rel="stylesheet" type="text/css"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
<style> | |
body { | |
font-family: 'Raleway'; | |
margin-top: 25px; | |
} | |
button .fa { | |
margin-right: 6px; | |
} | |
.table-text div { | |
padding-top: 6px; | |
} | |
</style> | |
<script> | |
$(function () { | |
$('#task-name').focus(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="container"> | |
<!-- Create Task Form... --> | |
<nav class="navbar navbar-default"> | |
<div class="container-fluid"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="#">Task List</a> | |
</div> | |
<div id="navbar" class="navbar-collapse collapse"> | |
<ul class="nav navbar-nav"> | |
| |
</ul> | |
</div> | |
</div> | |
</nav> | |
<!-- Current Tasks --> | |
</div> | |
@yield('content') | |
</body> | |
</html> |
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
Route::get('/', function () { | |
// | |
}); | |
Route::post('/task', function () { | |
// | |
}); | |
Route::delete('/task/{task}', function () { | |
// | |
}); |
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
@if (count($tasks) > 0) | |
<div class="panel panel-default"> | |
<div class="panel-heading"> | |
Current Tasks | |
</div> | |
<div class="panel-body"> | |
<table class="table table-striped task-table"> | |
<!-- Table Headings --> | |
<thead> | |
<tr> | |
<th>Task</th> | |
<th> </th> | |
</tr> | |
</thead> | |
<!-- Table Body --> | |
<tbody> | |
@foreach ($tasks as $task) | |
<tr> | |
<!-- Task Name --> | |
<td class="table-text"> | |
<div>{{ $task->name }}</div> | |
</td> | |
<td> | |
<!-- TODO: Delete Button --> | |
</td> | |
</tr> | |
@endforeach | |
</tbody> | |
</table> | |
</div> | |
</div> | |
@endif |
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
$task->delete(); | |
return redirect('/'); |
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
@if (count($errors) > 0) | |
<!-- Form Error List --> | |
<div class="alert alert-danger"> | |
<strong>Whoops! Something went wrong!</strong> | |
<br><br> | |
<ul> | |
@foreach ($errors->all() as $error) | |
<li>{{ $error }}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif |
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
$tasks = Task::orderBy('created_at', 'asc')->get(); | |
return view('task', [ | |
'tasks' => $tasks // このデータがtask.blade.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
use App\Task; | |
use Illuminate\Http\Request; |
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
$validator = Validator::make($request->all(), [ | |
'name' => 'required|max:10', | |
]); | |
if ($validator->fails()) { | |
return redirect('/') | |
->withInput() | |
->withErrors($validator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment