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?

【Laravel】flynsarmy/csv-seederで「Class "DB" not found」というエラーが出る際の対処法

Last updated at Posted at 2024-11-17

自分用

エラーの内容

  Class "DB" not found

  at vendor/flynsarmy/csv-seeder/src/CsvSeeder.php:235
    231         $mapping[0] = $this->stripUtf8Bom($mapping[0]);
    232
    233         // skip csv columns that don't exist in the database
    234         foreach ($mapping as $index => $fieldname) {
   235             if (!DB::connection($this->connection)->getSchemaBuilder()->hasColumn($this->table, $fieldname)) {
    236                 if (isset($mapping[$index])) {
    237                     unset($mapping[$index]);
    238                 }
    239             }

はじめに結論から

vendor/flynsarmy/csv-seeder/src/CsvSeeder.phpファイルの

namespace Flynsarmy\CsvSeeder;

use App;
use DB;

となっている部分を

namespace Flynsarmy\CsvSeeder;

use App;
use Illuminate\Support\Facades\DB;

こうする。
あと、作ったSeeder.phpファイルにも use Illuminate\Support\Facades\DB;を宣言させるのをお忘れなく。

参考

でも・・・

この方法で問題ないんでしょうか(vendor/直下の読み取り専用になってるファイルを編集した事なんてなかったもので・・・)

他に何かご提案などありましたらコメント欄でご教授いただけますと幸いです。宜しくお願いします。

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?