Page 70 - Laravel5_v1
P. 70
้
้
้
ิ
2. เปดไฟล์ BooksController.php ที เมธอด edit($id) ใหเขียนโคดเพื อแสดงเฉพาะแถวที ส่งมาพรอมทั ง render view ดวย ดังนี
้
public function edit($id) {
$book = Books::findOrFail($id);
return view('books.edit', ['book' => $book]);
}
ั
์
์
้
์
3. มาที โฟลเดอรของ views ใหสรางไฟล edit.blade.php ในโฟลเดอร books เพื อรองรบการ render จาก Controller ดังนี
้
ี
้
้
้
้
์
ื
4. ในการแกไขขอมูลเราจะใชวิธที เรยกว่า Model Binding หรอการผูกค่าโมเดลเขากับ input ต่างๆในฟอรม ดังนี
ี
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
้
้
<div class="panel-heading">แกไขขอมูลหนังสือ {{ $book->title }}</div>
<div class="panel-body">
@if (count($errors) > 0)
<div class="alert alert-warning">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<?= Form::model($book, array('url' => 'books/' . $book->id,
'method' => 'put')) ?>
<div class="col-xs-8">