私はCalendarServiceでlaravelプロジェクトを持っており、そのサービスを私のコントローラに注入します。建設業者では私はこのような何か:Laravel dependecy injection Auth ::
CalendarService.php
/** @var Collection|Timelog[] */
private $timelogs;
public function __construct()
{
$this->currentRoute = URL::to('/') . "/home";
$this->timelogs = Auth::user()->timelogs()->get();
$this->currentDay = 0;
}
HomeController.php
/** @var CalendarService */
protected $calenderService;
public function __construct
(
CalendarService $calendarService
)
{
$this->calenderService = $calendarService;
}
をそして私は、このエラーにメンバ関数timelogsへ
このコード行についてコールを取得します()on null
:
Auth::user()->timelogs()->get();
私は、誰もが任意のヘルプははるかに高く評価され、ここで何が起こっているか知っています私のサービス
でuse Illuminate\Support\Facades\Auth;
を使用していました!
ありがとうございます!
'Auth :: user()'が空であるということは、ユーザーがログインしていないことを意味します。あなたはユーザーがログインしていることを確認していますか? –
@Sauminiうん、確信しているよ: –
@ニコラスハハハは、遅れたコードが遅れてしまったコードを覚えています。Laravelは、遅れて遅れています。これは、コントローラのインジェクションをシミュレートしています... –