Skip to content

Commit

Permalink
Part 17 - Model/Form binding and creating an update form
Browse files Browse the repository at this point in the history
  • Loading branch information
jacurtis committed Mar 6, 2016
1 parent 1fafdab commit 0c4cbf9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public function show($id)
*/
public function edit($id)
{
//
// find the post in the database and save as a var
$post = Post::find($id);
// return the view and pass in the var we previously created
return view('posts.edit')->withPost($post);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.btn-h1-spacing {
margin-top: 18px;
}

.form-spacing-top {
margin-top: 30px;
}
43 changes: 43 additions & 0 deletions resources/views/posts/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@extends('main')

@section('title', '| Edit Blog Post')

@section('content')

<div class="row">
{!! Form::model($post, ['route' => ['posts.update', $post->id]]) !!}
<div class="col-md-8">
{{ Form::label('title', 'Title:') }}
{{ Form::text('title', null, ["class" => 'form-control input-lg']) }}

{{ Form::label('body', "Body:", ['class' => 'form-spacing-top']) }}
{{ Form::textarea('body', null, ['class' => 'form-control']) }}
</div>

<div class="col-md-4">
<div class="well">
<dl class="dl-horizontal">
<dt>Created At:</dt>
<dd>{{ date('M j, Y h:ia', strtotime($post->created_at)) }}</dd>
</dl>

<dl class="dl-horizontal">
<dt>Last Updated:</dt>
<dd>{{ date('M j, Y h:ia', strtotime($post->updated_at)) }}</dd>
</dl>
<hr>
<div class="row">
<div class="col-sm-6">
{!! Html::linkRoute('posts.show', 'Cancel', array($post->id), array('class' => 'btn btn-danger btn-block')) !!}
</div>
<div class="col-sm-6">
{!! Html::linkRoute('posts.update', 'Save Changes', array($post->id), array('class' => 'btn btn-success btn-block')) !!}
</div>
</div>

</div>
</div>
{!! Form::close() !!}
</div> <!-- end of .row (form) -->

@stop

0 comments on commit 0c4cbf9

Please sign in to comment.