LoginSignup
1
1

More than 1 year has passed since last update.

【Laravel】複数のSQL文が書かれたsqlファイルをシーダーで取り込む

Last updated at Posted at 2022-12-16

概要

DBから吐き出したSQLをseederで取り込みたい時に使用した

sqlディレクトリを作ってそこにsqlファイルをぶちこみ、

public function run()
{
    $path = 'database/sql/hogehoge.sql';
    DB::unprepared(file_get_contents($path));
}

DB::unprepared

大量のSQLや複数のSQL文を実行できますが危ない点もあり
スクリーンショット 2022-12-09 12.07.09.png

1
1
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
1
1