Add
use DB;
or do
\DB:table($table)->truncate();
Summer Sale! All accounts are 50% off this week.
My seeder is not running as the method 'table' in the DB facade is undefined, refer below. I am having trouble resolving why?
(L5.1)
DB:table($table)->truncate();
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder{
protected $toTruncate = ['articles'];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
foreach ($this->toTruncate as $table) {
DB::table($table)->truncate();
}
Model::reguard();
}
}
@4xjbh There are several ways for accessing Facade.
'DB' is alias of 'Illuminate\Support\Facades\DB', .. check in config/app.php
hence \DB means '\Illuminate\Support\Facades\DB' - fully qualified name space.
Laravel 5 uses psr-4 class loading where you need fully qualified class names.
see .. http://www.php-fig.org/psr/psr-4/ hence first '' means it starts searching from root namespace- and includes vendor packages. If you remove '' then it searches in your own package and didn't get Illuminate\Support\Facades\DB.
Please or to participate in this conversation.