Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/socialment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
],

'models' => [
// If you want to use a custom connected_account model, you can specify it here.
'connected_account' => \ChrisReedIO\Socialment\Models\ConnectedAccount::class,

// If you want to use a custom user model, you can specify it here.
'user' => '\App\Models\User',
],

// The table name for the connected_accounts table
'table_name' => 'connected_accounts',

];
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return new class extends Migration
{
public function up()
{
Schema::create('connected_accounts', function (Blueprint $table) {
Schema::create(config('socialment.table_name', 'connected_accounts'), function (Blueprint $table) {
$table->id();

$table->foreignId('user_id')->constrained()->cascadeOnDelete();
Expand Down
12 changes: 12 additions & 0 deletions src/Models/ConnectedAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Config;

/**
* @property string $provider
Expand Down Expand Up @@ -32,6 +33,17 @@ class ConnectedAccount extends Model
'expires_at',
];

public function __construct(array $attributes = [])
{
$config = Config::get('socialment');

if (isset($config['table_name'])) {
$this->setTable($config['table_name']);
}

parent::__construct($attributes);
}

public function user(): BelongsTo
{
return $this->belongsTo(config('socialment.models.user'));
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasConnectedAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ trait HasConnectedAccounts
{
public function connectedAccounts(): HasMany
{
return $this->hasMany(ConnectedAccount::class);
return $this->hasMany(config('socialment.models.connected_account', ConnectedAccount::class));
}
}