Skip to content

Commit

Permalink
Look for App\Models\User before App\User in provider
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviqv committed Feb 28, 2021
1 parent a3ac873 commit 057e7f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/Models/Member_AppModelsUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PanicHD\PanicHD\Models;

use App\Models\User;

This comment has been minimized.

Copy link
@jschlies

jschlies Dec 20, 2022

Can this be made into a parameter?? We do not use the typical Laravel namespace scheme. Ditto for APp/Http/Controller>

Any advice??? I'd rather not create a fork.

use PanicHD\PanicHD\Traits\MemberTrait;

class Member_AppModelsUser extends User
{
use MemberTrait;

protected $table = 'users';
}
17 changes: 14 additions & 3 deletions src/PanicHDServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ public function boot()

// Alias for Member model
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$member_model_class = 'PanicHD\PanicHD\Models\Member';
if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1 and Setting::grab('member_model_class') != 'default') {
// TODO: Check Class existence before using it. Add in cache to avoid this checks in every load
if (Schema::hasTable('panichd_settings') and Setting::where('slug', 'member_model_class')->count() == 1) {
$member_model_class = Setting::grab('member_model_class');
}

if (!isset($member_model_class) or $member_model_class == 'default'){
$member_model_class = Cache::remember('panichd::provider_member_class', 3600, function () {
// Check App\Models\User existence first
if (class_exists('\App\Models\User')){
return 'PanicHD\PanicHD\Models\Member_AppModelsUser';

}else{
// Inherit from App\User as default
return 'PanicHD\PanicHD\Models\Member_AppUser';
}
});
}

$loader->alias('PanicHDMember', $member_model_class);

$this->loadTranslationsFrom(__DIR__.'/Translations', 'panichd');
Expand Down

0 comments on commit 057e7f3

Please sign in to comment.