Page 74 - Laravel5_v1
P. 74
$book->save(); */
$book->update($request->all()); //mass asignment , define $fillable
(model)
return redirect()->action('BooksController@index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$book = Books::find($id);
if ($book->image != 'nopic.jpg') {
File::delete(public_path() . '\\images\\' . $book->image);
File::delete(public_path() . '\\images\\resize\\' . $book->image);
}
$book->delete();
return redirect()->action('BooksController@index');
}
}
ี
้
6. เพียงเท่านี เรากสามารถแกไขขอมูลไดเรยบรอย
้
็
้
้
ั
ื
้
การลบขอมูลหนงสอ (books)
์
้
ิ
ั
การลบขอมูลเช่นเดียวกันใหเราเพิ มคอลัมนอีก 1 คอลัมน เปดไฟล์ resources\views\books\index.blade.php อีกคร งเพื อแทรกคอลัมน ์
้
์
ใหกับตาราง สําหรบใชในการลบมีขั นตอน ดังนี
้
้
ั
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
้
<?= link_to('books/create', $title = 'เพิ มขอมูล', ['class' => 'btn btn-
primary'], $secure = null); ?>
<hr>