File tree 6 files changed +113
-20
lines changed
6 files changed +113
-20
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class extends Migration
8
+ {
9
+ public function up()
10
+ {
11
+ Schema::create('csv_imports', function (Blueprint $table) {
12
+ $table->id();
13
+ $table->morphs('importable');
14
+ $table->foreignId('user_id')->constrained()->nullable();
15
+ $table->string('file_path');
16
+ $table->string('file_name');
17
+ $table->unsignedBigInteger('total_rows');
18
+ $table->unsignedBigInteger('processed_rows')->default(0);
19
+ $table->datetime('completed_at')->nullable();
20
+ $table->timestamps();
21
+ });
22
+ }
23
+ };
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Coderflex \LaravelCsv \Concerns ;
4
+
5
+ use Coderflex \LaravelCsv \Models \Import ;
6
+ use Illuminate \Database \Eloquent \Relations \MorphMany ;
7
+
8
+ trait HasCsvImports
9
+ {
10
+ /**
11
+ * Has imports relationshipt
12
+ *
13
+ * @return \Illuminate\Database\Eloquent\Relations\MorphMany
14
+ */
15
+ public function imports (): MorphMany
16
+ {
17
+ return $ this ->morphMany (Import::class, 'importable ' );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Coderflex \LaravelCsv \Models ;
4
+
5
+ use Illuminate \Database \Eloquent \Model ;
6
+ use Coderflex \LaravelCsv \Scopes ;
7
+
8
+ /**
9
+ * Coderflex\LaravelCsv\Models\Import
10
+ * @property int $id
11
+ * @property int|null $user_id
12
+ * @property string $file_path
13
+ * @property string $file_name
14
+ * @property int $total_rows
15
+ * @property int $processed_rows
16
+ * @property \Illuminate\Support\Carbon|null $completed_at
17
+ * @property \Illuminate\Support\Carbon|null $created_at
18
+ * @property \Illuminate\Support\Carbon|null $updated_at
19
+ */
20
+ class Import extends Model
21
+ {
22
+ use Scopes \ImportScope;
23
+
24
+ /**
25
+ * The table associated with the model.
26
+ *
27
+ * @var string
28
+ */
29
+ protected $ table = "csv_imports " ;
30
+
31
+ /**
32
+ * The attributes that are mass assignable.
33
+ *
34
+ * @var string[]
35
+ */
36
+ protected $ guarded = [];
37
+
38
+ public function importable ()
39
+ {
40
+ return $ this ->morphTo ();
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Coderflex \LaravelCsv \Scopes ;
4
+
5
+ use Illuminate \Database \Eloquent \Builder ;
6
+
7
+ trait ImportScope
8
+ {
9
+ /**
10
+ * Completed Status Scope
11
+ * @return \Illuminate\Database\Eloquent\Builder
12
+ *
13
+ */
14
+ public function scopeCompleted (Builder $ builder ): Builder
15
+ {
16
+ return $ builder ->whereNotNull ('completed_at ' );
17
+ }
18
+
19
+ /**
20
+ * Not Completed Status Scope
21
+ * @return \Illuminate\Database\Eloquent\Builder
22
+ *
23
+ */
24
+ public function scopeNotCompleted (Builder $ builder ): Builder
25
+ {
26
+ return $ builder ->whereNull ('completed_at ' );
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function getEnvironmentSetUp($app)
37
37
{
38
38
config ()->set ('database.default ' , 'testing ' );
39
39
40
- $ migration = include __DIR__ .'/../database/migrations/create_csv_table .php.stub ' ;
40
+ $ migration = include __DIR__ .'/../database/migrations/create_csv_imports_table .php.stub ' ;
41
41
$ migration ->up ();
42
42
43
43
$ migration = include __DIR__ .'/Database/Migrations/create_customers_table.php ' ;
You can’t perform that action at this time.
0 commit comments