Skip to content

Commit d325cb4

Browse files
committed
[Updated] Core modules and migration
1 parent e384c19 commit d325cb4

34 files changed

+931
-558
lines changed

composer.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,30 @@
2626
"php": "^8.1",
2727
"ext-json": "*",
2828
"barryvdh/laravel-dompdf": "^2.0",
29-
"coderstm/laravel-installer": "^2.1",
29+
"coderstm/laravel-installer": "^2.2",
3030
"creativeorange/gravatar": "^1.0",
3131
"doctrine/dbal": "^3.4",
3232
"hisorange/browser-detect": "^4.5",
33-
"illuminate/console": "^9.21|^10.0",
34-
"illuminate/contracts": "^9.21|^10.0",
35-
"illuminate/database": "^9.21|^10.0",
36-
"illuminate/support": "^9.21|^10.0",
33+
"illuminate/console": "^11.0",
34+
"illuminate/contracts": "^11.0",
35+
"illuminate/database": "^11.0",
36+
"illuminate/support": "^11.0",
3737
"kreait/firebase-php": "^7.9",
38-
"laravel/cashier": "^14.0",
39-
"laravel/sanctum": "^3.2",
38+
"laravel/cashier": "^15.0",
39+
"laravel/sanctum": "^4.0",
40+
"league/csv": "^9.15",
4041
"league/iso3166": "^4.3",
4142
"simplesoftwareio/simple-qrcode": "^4.2",
4243
"spatie/laravel-sluggable": "^3.4",
43-
"stevebauman/location": "^6.5",
44+
"stevebauman/location": "^7.2.0",
4445
"twilio/sdk": "^7.16"
4546
},
4647
"require-dev": {
4748
"mockery/mockery": "^1.0",
48-
"nunomaduro/collision": "^7.0",
49-
"orchestra/testbench": "^7.0|^8.0",
49+
"nunomaduro/collision": "^8.1",
50+
"orchestra/testbench": "^9.0",
5051
"phpstan/phpstan": "^1.10",
51-
"phpunit/phpunit": "^9.0"
52+
"phpunit/phpunit": "^10.4"
5253
},
5354
"autoload": {
5455
"psr-4": {

config/coderstm.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
'domain' => env('APP_DOMAIN', null),
17-
'app_domain' => env('APP_DOMAIN', null),
1817
'web_prefix' => env('APP_WEB_PREFIX', 'app'),
1918
'api_prefix' => env('APP_API_PREFIX', 'api'),
2019
'tunnel_domain' => env('TUNNEL_WEB_DOMAIN', null),

database/factories/AdminFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function definition()
2525
'first_name' => fake()->firstName(),
2626
'last_name' => fake()->lastName(),
2727
'email' => fake()->safeEmail(),
28+
'phone_number' => fake()->e164PhoneNumber(),
2829
'email_verified_at' => now(),
2930
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
3031
'remember_token' => Str::random(10),

database/factories/ReplyFactory.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Coderstm\Database\Factories;
4+
5+
use Coderstm\Coderstm;
6+
use Coderstm\Models\Enquiry\Reply;
7+
use Illuminate\Database\Eloquent\Factories\Factory;
8+
9+
class ReplyFactory extends Factory
10+
{
11+
/**
12+
* The name of the factory's corresponding model.
13+
*
14+
* @var class-string<\Illuminate\Database\Eloquent\Model|TModel>
15+
*/
16+
protected $model = Reply::class;
17+
18+
/**
19+
* Define the model's default state.
20+
*
21+
* @return array
22+
*/
23+
public function definition()
24+
{
25+
return [
26+
'message' => fake()->paragraph(),
27+
'user_id' => Coderstm::$adminModel::inRandomOrder()->first()->id,
28+
];
29+
}
30+
}

database/factories/UserFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function definition()
3131
'last_name' => fake()->lastName(),
3232
'email' => fake()->unique()->safeEmail,
3333
'gender' => $gender,
34-
'phone_number' => fake()->phoneNumber(),
34+
'phone_number' => fake()->e164PhoneNumber(),
3535
'email_verified_at' => now(),
3636
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
3737
'remember_token' => Str::random(10),

database/migrations/2014_10_12_000001_create_admins_table.php

+2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public function up()
2020
$table->id();
2121
$table->string('first_name')->nullable();
2222
$table->string('last_name')->nullable();
23+
$table->string('gender')->nullable();
2324
$table->string('email')->unique();
2425
$table->string('phone_number')->nullable();
2526
$table->timestamp('email_verified_at')->nullable();
2627
$table->string('password');
28+
$table->string('status')->nullable();
2729
$table->boolean('is_active')->nullable()->default(true);
2830
$table->boolean('is_supper_admin')->nullable()->default(false);
2931
$table->string('remember_token', 100)->nullable();

database/migrations/2021_09_11_193660_create_payment_methods_table.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@
1818
*/
1919
public function up()
2020
{
21-
if (!Schema::hasTable('payment_methods')) {
22-
Schema::create('payment_methods', function (Blueprint $table) {
23-
$table->id();
21+
if (Schema::hasTable('payment_methods')) return;
2422

25-
$table->string('name');
26-
$table->string('provider')->default('manual');
27-
$table->string('link')->nullable();
28-
$table->string('logo')->nullable();
29-
$table->text('description')->nullable();
30-
$table->{$this->jsonable()}('credentials')->nullable();
31-
$table->{$this->jsonable()}('methods')->nullable();
32-
$table->boolean('active')->default(false);
33-
$table->enum('capture', ['automatic', 'manual'])->nullable()->default('manual');
34-
$table->string('additional_details')->nullable();
35-
$table->string('payment_instructions')->nullable();
36-
$table->boolean('test_mode')->default(false);
37-
$table->string('transaction_fee')->default(0);
38-
$table->string('webhook')->nullable();
23+
Schema::create('payment_methods', function (Blueprint $table) {
24+
$table->id();
3925

40-
$table->timestamps();
41-
$table->softDeletes();
42-
});
43-
$this->setAutoIncrement('payment_methods');
44-
}
26+
$table->string('name');
27+
$table->string('provider')->default('manual');
28+
$table->string('link')->nullable();
29+
$table->string('logo')->nullable();
30+
$table->text('description')->nullable();
31+
$table->{$this->jsonable()}('credentials')->nullable();
32+
$table->{$this->jsonable()}('methods')->nullable();
33+
$table->boolean('active')->default(false);
34+
$table->enum('capture', ['automatic', 'manual'])->nullable()->default('manual');
35+
$table->string('additional_details')->nullable();
36+
$table->string('payment_instructions')->nullable();
37+
$table->boolean('test_mode')->default(false);
38+
$table->string('transaction_fee')->default(0);
39+
$table->string('webhook')->nullable();
40+
41+
$table->timestamps();
42+
$table->softDeletes();
43+
});
44+
$this->setAutoIncrement('payment_methods');
4545
}
4646
};

src/Http/Controllers/Auth/AuthController.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function login(Request $request, $guard = 'users')
4848

4949
// send login alert to user if smtp configured
5050
$user->notify(new UserLogin($loginLog));
51-
} catch (\Throwable $th) {
52-
report($th);
51+
} catch (\Exception $e) {
52+
report($e);
5353
}
5454

5555
// delete old token with requested device
@@ -125,7 +125,6 @@ public function signup(Request $request, $guard = 'users')
125125
public function logout(Request $request, $guard = 'users')
126126
{
127127
try {
128-
Auth::guard($guard)->logout();
129128
$request->user()->currentAccessToken()->delete();
130129
} catch (\Throwable $th) {
131130
report($th);

src/Http/Controllers/FileController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function download(Request $request)
185185
public function uploadFromSource(Request $request)
186186
{
187187
$rules = [
188-
'source' => 'required',
188+
'source' => 'required|url',
189189
];
190190

191191
$this->validate($request, $rules);

src/Http/Controllers/Subscription/SubscriptionController.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public function index(Request $request)
2929
$user = $this->user();
3030
$subscription = $user->subscription();
3131

32-
if ($user->is_free_forever || !$subscription) {
32+
if ($user->onGenericTrial()) {
33+
$trial_end = $user->trial_ends_at->format('M d, Y');
3334
return response()->json([
34-
'message' => trans('coderstm::messages.subscription.none'),
35+
'message' => "You're on trial until $trial_end, <strong>but you haven't subscribed to any plan yet</strong>. Please do so now to contine using the application even after your trial ends.",
3536
'upcomingInvoice' => false,
3637
], 200);
37-
} else if ($user->onGenericTrial()) {
38-
$trial_end = $user->trial_ends_at->format('M d, Y');
38+
} else if ($user->is_free_forever || !$subscription) {
3939
return response()->json([
40-
'message' => "You're on trial until $trial_end, <strong>but you haven't subscribed to any plan yet</strong>. Please do so now to contine using the application even after your trial ends.",
40+
'message' => trans('coderstm::messages.subscription.none'),
4141
'upcomingInvoice' => false,
4242
], 200);
4343
}
@@ -410,6 +410,7 @@ protected function user()
410410
if (request()->filled('user_id') && is_admin()) {
411411
return Coderstm::$userModel::findOrFail(request()->user_id);
412412
}
413+
413414
return user();
414415
}
415416

src/Models/Address.php

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Coderstm\Models;
44

5+
use Coderstm\Database\Factories\AddressFactory;
56
use Coderstm\Traits\Core;
67
use Illuminate\Database\Eloquent\Model;
78

@@ -51,4 +52,14 @@ public function getLabelAttribute()
5152
'postal_code',
5253
])->toArray());
5354
}
55+
56+
/**
57+
* Create a new factory instance for the model.
58+
*
59+
* @return \Illuminate\Database\Eloquent\Factories\Factory
60+
*/
61+
protected static function newFactory()
62+
{
63+
return AddressFactory::new();
64+
}
5465
}

src/Models/Admin.php

+69
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
use Coderstm\Traits\HasPermissionGroup;
1111
use Illuminate\Support\Facades\DB;
1212
use Illuminate\Foundation\Auth\User as Authenticatable;
13+
use Coderstm\Database\Factories\AdminFactory;
1314
use Illuminate\Notifications\Notifiable;
1415
use Illuminate\Contracts\Auth\MustVerifyEmail;
16+
use Coderstm\Exceptions\ImportFailedException;
17+
use Coderstm\Exceptions\ImportSkippedException;
18+
use League\ISO3166\ISO3166;
1519

1620
class Admin extends Authenticatable
1721
{
@@ -22,6 +26,7 @@ class Admin extends Authenticatable
2226
protected $fillable = [
2327
'first_name',
2428
'last_name',
29+
'gender',
2530
'email',
2631
'password',
2732
'phone_number',
@@ -138,4 +143,68 @@ public function getShortCodes(): array
138143
'{{ADMIN_PHONE_NUMBER}}' => $this->phone_number,
139144
];
140145
}
146+
147+
public static function getMappedAttributes(): array
148+
{
149+
return [
150+
"First Name" => 'first_name',
151+
"Surname" => 'last_name',
152+
"Gender" => 'gender',
153+
"Email Address" => 'email',
154+
"Phone Number" => 'phone_number',
155+
"Status" => 'status',
156+
"Password" => 'password',
157+
"Created At" => 'created_at',
158+
"Address Line1" => 'line1',
159+
"Address Line2" => 'line2',
160+
"Country" => 'country',
161+
"State" => 'state',
162+
"State Code" => 'state_code',
163+
"City" => 'city',
164+
"Postcode/Zip" => 'postal_code',
165+
];
166+
}
167+
168+
public static function createFromCsv(array $attributes = [], array $options = [])
169+
{
170+
$replaceByEmail = isset($options['email_overwrite']) && $options['email_overwrite'];
171+
$user = static::where('email', $attributes['email'])->first();
172+
173+
if (!$replaceByEmail && $user) {
174+
throw new ImportFailedException;
175+
} else if ($user && ($user->wasRecentlyUpdated || $user->wasRecentlyCreated)) {
176+
throw new ImportSkippedException;
177+
}
178+
179+
if (isset($attributes['password'])) {
180+
$attributes['password'] = bcrypt($attributes['password']);
181+
}
182+
183+
if (isset($attributes['country'])) {
184+
$country = (new ISO3166)->name($attributes['country']);
185+
$attributes['country_code'] = $country['alpha2'];
186+
}
187+
188+
$user = static::firstOrNew([
189+
'email' => $attributes['email']
190+
], $attributes);
191+
192+
if (isset($attributes['created_at']) && !empty($attributes['created_at'])) {
193+
$user->created_at = $attributes['created_at'];
194+
}
195+
196+
$user->save();
197+
198+
$user->updateOrCreateAddress($attributes);
199+
}
200+
201+
/**
202+
* Create a new factory instance for the model.
203+
*
204+
* @return \Illuminate\Database\Eloquent\Factories\Factory
205+
*/
206+
protected static function newFactory()
207+
{
208+
return AdminFactory::new();
209+
}
141210
}

src/Models/Cashier/PaymentMethod.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class PaymentMethod extends Model
2525
];
2626

2727
protected $casts = [
28-
'is_default' => 'boolean'
28+
'card' => 'json',
29+
'is_default' => 'boolean',
2930
];
3031

3132
public function markAsDefault()

src/Models/Enquiry.php

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Coderstm\Models;
44

55
use Coderstm\Coderstm;
6+
use Coderstm\Database\Factories\EnquiryFactory;
67
use Coderstm\Traits\Core;
78
use Coderstm\Enum\AppStatus;
89
use Coderstm\Traits\Fileable;
@@ -238,6 +239,16 @@ public function sendPushNotify($type = null)
238239
}
239240
}
240241

242+
/**
243+
* Create a new factory instance for the model.
244+
*
245+
* @return \Illuminate\Database\Eloquent\Factories\Factory
246+
*/
247+
protected static function newFactory()
248+
{
249+
return EnquiryFactory::new();
250+
}
251+
241252
protected static function booted()
242253
{
243254
parent::booted();

src/Models/Enquiry/Reply.php

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Coderstm\Events\EnquiryReplyCreated;
1313
use Illuminate\Database\Eloquent\Builder;
1414
use Coderstm\Jobs\SendWhatsappNotification;
15+
use Coderstm\Database\Factories\ReplyFactory;
1516
use Illuminate\Database\Eloquent\Factories\HasFactory;
1617

1718
class Reply extends Model
@@ -123,6 +124,16 @@ public function sendPushNotify($type = null)
123124
}
124125
}
125126

127+
/**
128+
* Create a new factory instance for the model.
129+
*
130+
* @return \Illuminate\Database\Eloquent\Factories\Factory
131+
*/
132+
protected static function newFactory()
133+
{
134+
return ReplyFactory::new();
135+
}
136+
126137
protected static function booted()
127138
{
128139
parent::booted();

0 commit comments

Comments
 (0)