Last active
November 3, 2016 13:18
-
-
Save peterfox/ddf772ce08f2f7128073d986570e4a73 to your computer and use it in GitHub Desktop.
Intro to Laravel Workshop 3/11/16
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="row"> | |
<div class="col-md-8 col-md-offset-2"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Tasks</div> | |
<div class="panel-body"> | |
<ul> | |
@foreach(Auth::user()->tasks()->get() as $task) | |
<li> | |
{{ $task->task }} | |
</li> | |
@endforeach | |
</ul> | |
</div> | |
</div> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Add a Task</div> | |
<div class="panel-body"> | |
<form method="post" action="/home/task" > | |
<div class="form-group"> | |
<label for="task">Task</label> | |
<input name="task" id="task" placeholder="I need to..." class="form-control" /> | |
</div> | |
{{ csrf_field() }} | |
<button class="btn btn-default" type="submit"> | |
Add | |
</button> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</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
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Task extends Model | |
{ | |
protected $fillable = [ | |
'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
<?php | |
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateTasksTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('tasks', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->integer('user_id'); | |
$table->text('task'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* 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
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
class TaskController extends Controller | |
{ | |
public function create(Request $request) | |
{ | |
$request->user()->tasks()->create($request->only(['task'])); | |
return redirect('/home'); | |
} | |
} |
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
<?php | |
namespace App; | |
use Illuminate\Notifications\Notifiable; | |
use Illuminate\Foundation\Auth\User as Authenticatable; | |
class User extends Authenticatable | |
{ | |
use Notifiable; | |
/** | |
* The attributes that are mass assignable. | |
* | |
* @var array | |
*/ | |
protected $fillable = [ | |
'name', 'email', 'password', | |
]; | |
/** | |
* The attributes that should be hidden for arrays. | |
* | |
* @var array | |
*/ | |
protected $hidden = [ | |
'password', 'remember_token', | |
]; | |
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
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| This file is where you may define all of the routes that are handled | |
| by your application. Just tell Laravel the URIs it should respond | |
| to using a Closure or controller method. Build something great! | |
| | |
*/ | |
Route::get('/', function () { | |
return view('welcome'); | |
}); | |
Auth::routes(); | |
Route::get('/home', 'HomeController@index'); | |
Route::post('/home/task', 'TaskController@create'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment