【发布时间】:2017-09-11 06:50:12
【问题描述】:
我无法在我的播种机类中使用 Auth。我需要为我的 saas 应用程序获取tenant_id 变量。这是我的播种机类。
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);
【问题讨论】:
-
试试
auth()->user()->tenant_id,反馈。 -
同样的错误,“非复合名称'Auth'的use语句对laravel无效”。
-
请发布完整文件
-
文档说 $user = Auth::user(); // 获取当前认证的用户。但是由于您在播种机中,因此您没有经过身份验证的用户?
-
我猜是这样,但我想使用 Artisan::call('db:seed'); 以编程方式调用我的播种机类;但无法使用 Auth 门面获取当前经过身份验证的用户tenant_id。