Skip to content

Commit 0c4cbf9

Browse files
committed
Part 17 - Model/Form binding and creating an update form
1 parent 1fafdab commit 0c4cbf9

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

app/Http/Controllers/PostController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public function show($id)
7979
*/
8080
public function edit($id)
8181
{
82-
//
82+
// find the post in the database and save as a var
83+
$post = Post::find($id);
84+
// return the view and pass in the var we previously created
85+
return view('posts.edit')->withPost($post);
8386
}
8487

8588
/**

public/css/styles.css

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.btn-h1-spacing {
22
margin-top: 18px;
3+
}
4+
5+
.form-spacing-top {
6+
margin-top: 30px;
37
}

resources/views/posts/edit.blade.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@extends('main')
2+
3+
@section('title', '| Edit Blog Post')
4+
5+
@section('content')
6+
7+
<div class="row">
8+
{!! Form::model($post, ['route' => ['posts.update', $post->id]]) !!}
9+
<div class="col-md-8">
10+
{{ Form::label('title', 'Title:') }}
11+
{{ Form::text('title', null, ["class" => 'form-control input-lg']) }}
12+
13+
{{ Form::label('body', "Body:", ['class' => 'form-spacing-top']) }}
14+
{{ Form::textarea('body', null, ['class' => 'form-control']) }}
15+
</div>
16+
17+
<div class="col-md-4">
18+
<div class="well">
19+
<dl class="dl-horizontal">
20+
<dt>Created At:</dt>
21+
<dd>{{ date('M j, Y h:ia', strtotime($post->created_at)) }}</dd>
22+
</dl>
23+
24+
<dl class="dl-horizontal">
25+
<dt>Last Updated:</dt>
26+
<dd>{{ date('M j, Y h:ia', strtotime($post->updated_at)) }}</dd>
27+
</dl>
28+
<hr>
29+
<div class="row">
30+
<div class="col-sm-6">
31+
{!! Html::linkRoute('posts.show', 'Cancel', array($post->id), array('class' => 'btn btn-danger btn-block')) !!}
32+
</div>
33+
<div class="col-sm-6">
34+
{!! Html::linkRoute('posts.update', 'Save Changes', array($post->id), array('class' => 'btn btn-success btn-block')) !!}
35+
</div>
36+
</div>
37+
38+
</div>
39+
</div>
40+
{!! Form::close() !!}
41+
</div> <!-- end of .row (form) -->
42+
43+
@stop

0 commit comments

Comments
 (0)