service-provider

Laravel - How to get current user in AppServiceProvider

一曲冷凌霜 提交于 2019-11-28 08:25:38
So I am usually getting the current user using Auth::user() and when I am determining if a user is actually logged in Auth::check . However this doesn't seem to work in my AppServiceProvider . I am using it to share data across all views. I var_dump both Auth::user() and Auth::check() while logged in and I get NULL and false . How can I get the current user inside my AppServiceProvider ? If that isn't possible, what is the way to get data that is unique for each user (data that is different according to the user_id ) across all views. Here is my code for clarification. if (Auth::check()) {

Laravel 4 - when to use service providers?

喜你入骨 提交于 2019-11-27 09:50:44
问题 I tried to google it but did not find detailed information. Service providers are a great way to group related IoC registrations in a single location. Think of them as a way to bootstrap components in your application. Not understanding from the documentation. Is this only needed when I create packages? So when I am regular developer and not making some packages to release in public - I don't need to care? 回答1: One of the keys to building a well architected Laravel application is learning to

Laravel - How to get current user in AppServiceProvider

主宰稳场 提交于 2019-11-27 05:48:23
问题 So I am usually getting the current user using Auth::user() and when I am determining if a user is actually logged in Auth::check . However this doesn't seem to work in my AppServiceProvider . I am using it to share data across all views. I var_dump both Auth::user() and Auth::check() while logged in and I get NULL and false . How can I get the current user inside my AppServiceProvider ? If that isn't possible, what is the way to get data that is unique for each user (data that is different