-
-
Save Thijmen/1e3039ded96878e776fa4c1f889dbad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Repositories\ClubRepository; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->app->singleton(ClubRepository::class, function($app) { | |
return new ClubRepository($this->app['session']); | |
}); | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Repositories; | |
use App\Club; | |
use App\ClubFeature; | |
use App\Http\Requests\Request; | |
use App\Membershipnumberalgorithm; | |
use App\User; | |
use Carbon\Carbon; | |
use Crypt; | |
use Illuminate\Session\SessionManager; | |
use Illuminate\Session\Store; | |
use Illuminate\Support\Facades\Auth; | |
use Session; | |
class ClubRepository | |
{ | |
/** | |
* @var \Session | |
*/ | |
protected $session; | |
/** | |
* @var \App\User | |
*/ | |
protected $user; | |
/** | |
* @var \App\Club | |
*/ | |
protected $currentClub; | |
private $forceReload = false; | |
public function __construct(SessionManager $session) { | |
$this->currentClubSessionKey = config('clubmanager.session.current_club'); | |
$this->session = $session; | |
$this->user = Auth::user(); | |
} | |
public function getCurrentUser() { | |
return $this->user; | |
} | |
/** | |
* @return Club | |
*/ | |
public function getCurrentClub() { | |
if ( ! is_null( $this->currentClub ) && ! $this->forceReload) { | |
return $this->currentClub; | |
} | |
$clubId = $this->session->get($this->currentClubSessionKey, null); | |
if ( $clubId == null ) { | |
return null; | |
} | |
$this->currentClub = Club::where('id', $clubId)->first(); | |
return $this->currentClub; | |
} | |
public function getClubsOfUser() { | |
if ( $this->user->hasRole('admin')) { | |
return Club::all(); | |
} | |
return $this->user->clubs; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Notification; | |
use App\Repositories\ActivityRepository; | |
use App\Repositories\ClubRepository; | |
use App\Repositories\NewsRepository; | |
use Illuminate\Http\Request; | |
use App\Http\Requests; | |
use App\Http\Controllers\Controller; | |
use Spatie\Activitylog\Models\Activity; | |
class DashboardController extends Controller | |
{ | |
/** | |
* @var ClubRepository | |
*/ | |
private $clubRepository; | |
/** | |
* @var NewsRepository | |
*/ | |
private $newsRepository; | |
/** | |
* @var ActivityRepository | |
*/ | |
private $activityRepository; | |
public function __construct(ClubRepository $clubRepository, NewsRepository $newsRepository, ActivityRepository $activityRepository) { | |
$this->clubRepository = $clubRepository; | |
$this->newsRepository = $newsRepository; | |
$this->activityRepository = $activityRepository; | |
} | |
public function getIndex() { | |
$club = $this->clubRepository->getCurrentClub(); | |
return view('dashboard.index', compact('club')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment