0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP(Laravel)でレコードのinsert, update, delete

Last updated at Posted at 2020-03-20

insert

DB::table('テーブル名')->insert(配列データ);

update

DB::table('テーブル名')->where('更新対象を検索')->update(配列データ);
    $params = [
      'id' => $request->id,
      'name' => $request->name,
      'email' => $request->email,
      'age' => $request->age
    ];

delete

# 使い方
DB::table('テーブル名')->where(検索条件)->delete();
# 削除ルーティング
Route::post('/hoge/delete', 'HogeController@delete');
HogeController.php
  public function delete(Request $request){
    $id = $request->delete_id;
    $person = DB::table('people')->where('id', $id);
    $person->delete();
    return redirect('/hello');
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?