Raw SQL Query
Route::get('/insert', function(){
DB::insert('insert into posts(title, content) values(?, ?)', ['php with laravel', 'Laravel is the best thing that happen to PHP']);
});
mysql> select * from posts;
+—-+——————+———————————————-+————+————+———-+
| id | title | content | created_at | updated_at | is_admin |
+—-+——————+———————————————-+————+————+———-+
| 1 | php with laravel | Laravel is the best thing that happen to PHP | NULL | NULL | 0 |
+—-+——————+———————————————-+————+————+———-+
1 row in set (0.00 sec)
以下のようにclassに対して値を入れてsave();とする方法とは異なる
public function store(Request $request){
$post = new Post();
$post->title = $request->title;
$post->body = $request->body;
$post->save();
return redirect('/');
}
sqlに慣れていると、Raw SQL Queryの方が馴染みがあります。