2017-09-11 37 views
0

我无法在我的播种机类中使用Auth。我需要为我的saas应用程序获取tenant_id变量。这是我的播种班。非复合名称'Auth'的使用声明不起作用laravel

use Illuminate\Database\Seeder; 
use App\AccountType; 
use Auth; 

class AccountTypeTableSeeder extends Seeder{ 

public function run() 
{ 

    $accountType = new AccountType; 
    $accountType->name = 'Travel Agent'; 
    $accountType->description = 'It is the description of the Travel Agent, so you write in detaisl about the account type.'; 
    $accountType->tenant_id = Auth::user()->tenant_id; 
    $accountType->save(); 


} 

}

我打电话

$this->call(AccountTypeTableSeeder::class); 
+0

尝试'AUTH() - >用户() - > tenant_id',回来报告。 – Gammer

+0

同样的错误,“非复合名称使用声明'Auth'没有影响laravel”。 – Wangchen

+0

请发布完整文件 – Anders

回答

0

在你的文件的顶部放:

use Illuminate\Support\Facades\Auth; 
+0

来发布上面的整个播种机类,我也尝试过使用Auth;两者都给出相同的错误。 – Wangchen

0

因为我需要的tenand_id,我用最后插入做到了以编程方式进行播种时获得tenant_id的用户ID。

Artisan::call('db:seed'); 

我用

User::latest()->first()->tenant_id;