Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — belongs-to-many-save-duplicate... ( 7c598a...7c7f5e )
by Pedro
31:33
created

testCreateBelongsToWithRelationName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.6333
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
4
5
use Backpack\CRUD\Tests\config\Models\Article;
6
use Backpack\CRUD\Tests\config\Models\Bang;
7
use Backpack\CRUD\Tests\config\Models\Comet;
8
use Backpack\CRUD\Tests\config\Models\Planet;
9
use Backpack\CRUD\Tests\config\Models\PlanetNonNullable;
10
use Backpack\CRUD\Tests\config\Models\Star;
11
use Backpack\CRUD\Tests\config\Models\Universe;
12
use Backpack\CRUD\Tests\config\Models\User;
13
use Faker\Factory;
14
use Illuminate\Database\Eloquent\Relations\Relation;
15
use Illuminate\Support\Arr;
16
use Illuminate\Support\Facades\Hash;
17
18
/**
19
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Create
20
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Relationships
21
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\FieldsProtectedMethods
22
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Update
23
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Input
24
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\MorphRelationships
25
 */
26
class CrudPanelCreateTest extends \Backpack\CRUD\Tests\config\CrudPanel\BaseDBCrudPanel
27
{
28
    private $nonRelationshipField = [
29
        'name' => 'field1',
30
        'label' => 'Field1',
31
    ];
32
33
    private $userInputFieldsNoRelationships = [
34
        [
35
            'name' => 'id',
36
            'type' => 'hidden',
37
        ], [
38
            'name' => 'name',
39
        ], [
40
            'name' => 'email',
41
            'type' => 'email',
42
        ], [
43
            'name' => 'password',
44
            'type' => 'password',
45
        ],
46
    ];
47
48
    private $articleInputFieldsOneToMany = [
49
        [
50
            'name' => 'id',
51
            'type' => 'hidden',
52
        ], [
53
            'name' => 'content',
54
        ], [
55
            'name' => 'tags',
56
        ], [
57
            'label' => 'Author',
58
            'type' => 'select',
59
            'name' => 'user_id',
60
            'entity' => 'user',
61
            'attribute' => 'name',
62
        ],
63
    ];
64
65
    private $userInputFieldsManyToMany = [
66
        [
67
            'name' => 'id',
68
            'type' => 'hidden',
69
        ], [
70
            'name' => 'name',
71
        ], [
72
            'name' => 'email',
73
            'type' => 'email',
74
        ], [
75
            'name' => 'password',
76
            'type' => 'password',
77
        ], [
78
            'label' => 'Roles',
79
            'type' => 'select_multiple',
80
            'name' => 'roles',
81
            'entity' => 'roles',
82
            'attribute' => 'name',
83
            'pivot' => true,
84
        ],
85
    ];
86
87
    private $userInputFieldsDotNotation = [
88
        [
89
            'name' => 'id',
90
            'type' => 'hidden',
91
        ], [
92
            'name' => 'name',
93
        ], [
94
            'name' => 'email',
95
            'type' => 'email',
96
        ], [
97
            'name' => 'password',
98
            'type' => 'password',
99
        ], [
100
            'label' => 'Roles',
101
            'type' => 'relationship',
102
            'name' => 'roles',
103
            'entity' => 'roles',
104
            'attribute' => 'name',
105
        ], [
106
            'label' => 'Street',
107
            'name' => 'street',
108
            'entity' => 'accountDetails.addresses',
109
            'attribute' => 'street',
110
        ],
111
    ];
112
113
    private $userInputHasOneRelation = [
114
        [
115
            'name' => 'accountDetails.nickname',
116
        ],
117
        [
118
            'name' => 'accountDetails.profile_picture',
119
        ],
120
    ];
121
122
    private $articleInputBelongsToRelationName = [
123
        [
124
            'name' => 'user',
125
        ],
126
    ];
127
128
    public function testCreate()
129
    {
130
        $this->crudPanel->setModel(User::class);
131
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
132
        $faker = Factory::create();
133
        $inputData = [
134
            'name' => $faker->name,
135
            'email' => $faker->safeEmail,
136
            'password' => Hash::make($faker->password()),
137
        ];
138
139
        $entry = $this->crudPanel->create($inputData);
140
141
        $this->assertInstanceOf(User::class, $entry);
142
        $this->assertEntryEquals($inputData, $entry);
143
        $this->assertEmpty($entry->articles);
144
    }
145
146
    public function testCreateWithOneToOneRelationship()
147
    {
148
        $this->crudPanel->setModel(User::class);
149
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
150
        $this->crudPanel->addFields($this->userInputHasOneRelation);
151
        $faker = Factory::create();
152
        $account_details_nickname = $faker->name;
153
        $inputData = [
154
            'name' => $faker->name,
155
            'email' => $faker->safeEmail,
156
            'password' => Hash::make($faker->password()),
157
            'accountDetails' => [
158
                'nickname' => $account_details_nickname,
159
                'profile_picture' => 'test.jpg',
160
            ],
161
        ];
162
        $entry = $this->crudPanel->create($inputData);
163
        $account_details = $entry->accountDetails()->first();
164
165
        $this->assertEquals($account_details->nickname, $account_details_nickname);
0 ignored issues
show
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
166
    }
167
168
    public function testCreateWithOneToOneRelationshipUsingRepeatableInterface()
169
    {
170
        $this->crudPanel->setModel(User::class);
171
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
172
        $this->crudPanel->addField([
173
            'name' => 'accountDetails',
174
            'fields' => [
175
                [
176
                    'name' => 'nickname',
177
                ],
178
                [
179
                    'name' => 'profile_picture',
180
                ],
181
            ],
182
        ]);
183
        $faker = Factory::create();
184
        $account_details_nickname = $faker->name;
185
        $inputData = [
186
            'name' => $faker->name,
187
            'email' => $faker->safeEmail,
188
            'password' => Hash::make($faker->password()),
189
            'accountDetails' => [
190
                ['nickname' => $account_details_nickname, 'profile_picture' => 'test.jpg'],
191
            ],
192
        ];
193
        $entry = $this->crudPanel->create($inputData);
194
        $account_details = $entry->accountDetails()->first();
195
196
        $this->assertEquals($account_details->nickname, $account_details_nickname);
0 ignored issues
show
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
197
    }
198
199
    public function testCreateBelongsToWithRelationName()
200
    {
201
        $this->crudPanel->setModel(Article::class);
202
        $this->crudPanel->addFields($this->articleInputFieldsOneToMany);
203
        $this->crudPanel->removeField('user_id');
204
        $this->crudPanel->addFields($this->articleInputBelongsToRelationName);
205
        $faker = Factory::create();
206
        $inputData = [
207
            'content' => $faker->text(),
208
            'tags' => $faker->words(3, true),
209
            'user' => 1,
210
            'metas' => null,
211
            'extras' => null,
212
            'cast_metas' => null,
213
            'cast_tags' => null,
214
            'cast_extras' => null,
215
        ];
216
        $entry = $this->crudPanel->create($inputData);
217
        $userEntry = User::find(1);
0 ignored issues
show
Unused Code introduced by
The assignment to $userEntry is dead and can be removed.
Loading history...
218
        $article = Article::where('user_id', 1)->with('user')->get()->last();
219
        $this->assertEquals($article->user_id, $entry->user_id);
220
        $this->assertEquals($article->id, $entry->id);
221
    }
222
223
    public function testCreateWithOneToManyRelationship()
224
    {
225
        $this->crudPanel->setModel(Article::class);
226
        $this->crudPanel->addFields($this->articleInputFieldsOneToMany);
227
        $faker = Factory::create();
228
        $inputData = [
229
            'content' => $faker->text(),
230
            'tags' => $faker->words(3, true),
231
            'user_id' => 1,
232
            'metas' => null,
233
            'extras' => null,
234
            'cast_metas' => null,
235
            'cast_tags' => null,
236
            'cast_extras' => null,
237
        ];
238
239
        $entry = $this->crudPanel->create($inputData);
240
        $userEntry = User::find(1);
0 ignored issues
show
Unused Code introduced by
The assignment to $userEntry is dead and can be removed.
Loading history...
241
        $article = Article::where('user_id', 1)->with('user')->get()->last();
242
        $this->assertEntryEquals($inputData, $entry);
243
        $this->assertEquals($article->user_id, $entry->user_id);
244
        $this->assertEquals($article->id, $entry->id);
245
    }
246
247
    public function testCreateWithManyToManyRelationship()
248
    {
249
        $this->crudPanel->setModel(User::class);
250
        $this->crudPanel->addFields($this->userInputFieldsManyToMany);
251
        $faker = Factory::create();
252
        $inputData = [
253
            'name' => $faker->name,
254
            'email' => $faker->safeEmail,
255
            'password' => Hash::make($faker->password()),
256
            'remember_token' => null,
257
            'roles' => [1, 2],
258
        ];
259
260
        $entry = $this->crudPanel->create($inputData);
261
262
        $this->assertInstanceOf(User::class, $entry);
263
        $this->assertEntryEquals($inputData, $entry);
264
    }
265
266
    public function testGetRelationFields()
267
    {
268
        $this->markTestIncomplete('Not correctly implemented');
269
270
        $this->crudPanel->setModel(User::class);
271
        $this->crudPanel->addFields($this->userInputFieldsManyToMany, 'create');
272
273
        // TODO: fix method and documentation. when 'both' is passed as the $form value, the getRelationFields searches
274
        //       for relationship fields in the update fields.
275
        $relationFields = $this->crudPanel->getRelationFields('both');
276
277
        $this->assertEquals($this->crudPanel->create_fields['roles'], Arr::last($relationFields));
278
    }
279
280
    public function testGetRelationFieldsCreateForm()
281
    {
282
        $this->crudPanel->setModel(User::class);
283
        $this->crudPanel->setOperation('create');
284
        $this->crudPanel->addFields($this->userInputFieldsManyToMany);
285
286
        $relationFields = $this->crudPanel->getRelationFields();
287
288
        $this->assertEquals($this->crudPanel->get('create.fields')['roles'], Arr::last($relationFields));
289
    }
290
291
    public function testGetRelationFieldsUpdateForm()
292
    {
293
        $this->crudPanel->setModel(User::class);
294
        $this->crudPanel->setOperation('update');
295
        $this->crudPanel->addFields($this->userInputFieldsManyToMany);
296
297
        $relationFields = $this->crudPanel->getRelationFields();
298
299
        $this->assertEquals($this->crudPanel->get('update.fields')['roles'], Arr::last($relationFields));
300
    }
301
302
    public function testGetRelationFieldsUnknownForm()
303
    {
304
        $this->markTestIncomplete('Not correctly implemented');
305
306
        $this->expectException(\InvalidArgumentException::class);
307
308
        $this->crudPanel->setModel(User::class);
309
        $this->crudPanel->addFields($this->userInputFieldsManyToMany);
310
311
        // TODO: this should throw an invalid argument exception but instead it searches for relationship fields in the
312
        //       update fields.
313
        $this->crudPanel->getRelationFields('unknownForm');
314
    }
315
316
    public function testGetRelationFieldsDotNotation()
317
    {
318
        $this->crudPanel->setModel(User::class);
319
        $this->crudPanel->setOperation('create');
320
321
        $this->crudPanel->addFields($this->userInputFieldsDotNotation);
322
323
        //get all fields with a relation
324
        $relationFields = $this->crudPanel->getRelationFields();
325
326
        $this->assertEquals($this->crudPanel->get('create.fields')['street'], Arr::last($relationFields));
327
    }
328
329
    public function testCreateHasOneRelations()
330
    {
331
        $this->crudPanel->setModel(User::class);
332
        $this->crudPanel->setOperation('create');
333
334
        $this->crudPanel->addFields($this->userInputHasOneRelation);
335
        $faker = Factory::create();
336
337
        $inputData = [
338
            'name' => $faker->name,
339
            'email' => $faker->safeEmail,
340
            'password' => Hash::make($faker->password()),
341
            'remember_token' => null,
342
            'roles' => [1, 2],
343
            'accountDetails' => [
344
                'nickname' => 'i_have_has_one',
345
                'profile_picture' => 'simple_picture.jpg',
346
            ],
347
        ];
348
        $entry = $this->crudPanel->create($inputData);
349
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
350
        $account_details = $entry->accountDetails()->first();
351
352
        $this->assertEquals($account_details->nickname, 'i_have_has_one');
0 ignored issues
show
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property nickname does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
353
    }
354
355
    public function testGetRelationFieldsNoRelations()
356
    {
357
        $this->crudPanel->addField($this->nonRelationshipField);
358
359
        $relationFields = $this->crudPanel->getRelationFields();
360
361
        $this->assertEmpty($relationFields);
362
    }
363
364
    public function testGetRelationFieldsNoFields()
365
    {
366
        $relationFields = $this->crudPanel->getRelationFields();
367
368
        $this->assertEmpty($relationFields);
369
    }
370
371
    public function testGetRelationFieldsWithPivot()
372
    {
373
        $this->crudPanel->setModel(User::class);
374
        $this->crudPanel->setOperation('create');
375
        $this->crudPanel->addFields($this->userInputFieldsDotNotation);
376
377
        $relationFields = $this->crudPanel->getRelationFieldsWithPivot();
378
        $this->assertEquals($this->crudPanel->get('create.fields')['roles'], Arr::first($relationFields));
379
    }
380
381
    public function testGetRelationFieldsWithPivotNoRelations()
382
    {
383
        $this->crudPanel->setModel(User::class);
384
        $this->crudPanel->setOperation('create');
385
        $this->crudPanel->addFields($this->nonRelationshipField);
386
387
        $relationFields = $this->crudPanel->getRelationFieldsWithPivot();
388
389
        $this->assertEmpty($relationFields);
390
    }
391
392
    public function testMorphToManySelectableRelationship()
393
    {
394
        $this->crudPanel->setModel(User::class);
395
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

395
        $this->crudPanel->/** @scrutinizer ignore-call */ 
396
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
396
        $this->crudPanel->addField(['name' => 'bills'], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

396
        $this->crudPanel->/** @scrutinizer ignore-call */ 
397
                          addField(['name' => 'bills'], 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
397
398
        $faker = Factory::create();
399
        $inputData = [
400
            'name' => $faker->name,
401
            'email' => $faker->safeEmail,
402
            'password' => Hash::make($faker->password()),
403
            'remember_token' => null,
404
            'bills' => [1],
405
        ];
406
407
        $entry = $this->crudPanel->create($inputData);
408
409
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
410
411
        $this->assertCount(1, $entry->bills);
412
413
        $this->assertEquals(1, $entry->bills()->first()->id);
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
414
415
        $inputData['bills'] = [1, 2];
416
417
        $this->crudPanel->update($entry->id, $inputData);
418
419
        $this->assertCount(2, $entry->fresh()->bills);
420
421
        $this->assertEquals([1, 2], $entry->fresh()->bills->pluck('id')->toArray());
0 ignored issues
show
Bug introduced by
The method pluck() does not exist on Countable. It seems like you code against a sub-type of Countable such as RectorPrefix202405\Nette\Utils\Html or RectorPrefix202405\Nette\Utils\ArrayList or Illuminate\Pagination\LengthAwarePaginator or Illuminate\Http\Resources\Json\ResourceCollection or Nette\Utils\Html or Illuminate\Pagination\CursorPaginator or Carbon\CarbonPeriod or Illuminate\Pagination\Paginator or Nette\Iterators\CachingIterator or Nette\Utils\ArrayList or Illuminate\Support\ViewErrorBag or RectorPrefix202405\Nette\Iterators\CachingIterator or Illuminate\Support\Enumerable or Prologue\Alerts\AlertsMessageBag or Nette\Iterators\CachingIterator or RectorPrefix202405\Nette\Iterators\CachingIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

421
        $this->assertEquals([1, 2], $entry->fresh()->bills->/** @scrutinizer ignore-call */ pluck('id')->toArray());
Loading history...
422
    }
423
424
    public function testMorphToManyCreatableRelationship()
425
    {
426
        $this->crudPanel->setModel(User::class);
427
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

427
        $this->crudPanel->/** @scrutinizer ignore-call */ 
428
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
428
        $this->crudPanel->addField(['name' => 'recommends', 'subfields' => [
429
            [
430
                'name' => 'text',
431
            ],
432
        ]], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

432
        $this->crudPanel->/** @scrutinizer ignore-call */ 
433
                          addField(['name' => 'recommends', 'subfields' => [

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
433
434
        $faker = Factory::create();
435
        $inputData = [
436
            'name' => $faker->name,
437
            'email' => $faker->safeEmail,
438
            'password' => Hash::make($faker->password()),
439
            'remember_token' => null,
440
            'recommends' => [
441
                [
442
                    'recommends' => 1,
443
                    'text' => 'my pivot recommend field',
444
                ],
445
            ],
446
        ];
447
448
        $entry = $this->crudPanel->create($inputData);
449
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
450
451
        $this->assertCount(1, $entry->recommends);
452
453
        $this->assertEquals(1, $entry->recommends()->first()->id);
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
454
455
        $inputData['recommends'] = [
456
            [
457
                'recommends' => 2,
458
                'text' => 'I changed the recommend and the pivot text',
459
            ],
460
        ];
461
462
        $this->crudPanel->update($entry->id, $inputData);
463
464
        $this->assertCount(1, $entry->fresh()->recommends);
465
466
        $this->assertEquals(2, $entry->recommends()->first()->id);
467
468
        $this->assertEquals('I changed the recommend and the pivot text', $entry->fresh()->recommends->first()->pivot->text);
0 ignored issues
show
Bug introduced by
The method first() does not exist on Countable. It seems like you code against a sub-type of Countable such as RectorPrefix202405\Nette\Utils\Html or RectorPrefix202405\Nette\Utils\ArrayList or Illuminate\Pagination\LengthAwarePaginator or Illuminate\Http\Resources\Json\ResourceCollection or Nette\Utils\Html or League\CommonMark\Util\ArrayCollection or Illuminate\Pagination\CursorPaginator or RectorPrefix202405\Illum...acts\Support\MessageBag or Illuminate\Contracts\Support\MessageBag or Carbon\CarbonPeriod or Illuminate\Pagination\Paginator or Nette\Iterators\CachingIterator or Nette\Utils\ArrayList or Illuminate\Support\ViewErrorBag or RectorPrefix202405\Nette\Iterators\CachingIterator or Illuminate\Support\Enumerable or Ramsey\Collection\CollectionInterface or Ramsey\Collection\AbstractCollection or Ds\Map or Ds\Set or Ds\Sequence or Nette\Iterators\CachingIterator or RectorPrefix202405\Nette\Iterators\CachingIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

468
        $this->assertEquals('I changed the recommend and the pivot text', $entry->fresh()->recommends->/** @scrutinizer ignore-call */ first()->pivot->text);
Loading history...
469
    }
470
471
    public function testMorphToManyCreatableRelationshipWithMultiple()
472
    {
473
        $inputData = $this->getPivotInputData(['recommendsDuplicate' => [
474
                [
475
                    'recommendsDuplicate' => 1,
476
                    'text' => 'my pivot recommend field 1',
477
                ],
478
                [
479
                    'recommendsDuplicate' => 2,
480
                    'text' => 'my pivot recommend field 2',
481
                ],
482
                [
483
                    'recommendsDuplicate' => 1,
484
                    'text' => 'my pivot recommend field 1x1',
485
                ],
486
            ]
487
            ], true, true);
488
489
        $entry = $this->crudPanel->create($inputData);
490
491
        $entry = $entry->fresh();
492
493
        $this->assertCount(3, $entry->recommendsDuplicate);
494
        
495
        $this->assertEquals(1, $entry->recommendsDuplicate[0]->id);
496
        $this->assertEquals(1, $entry->recommendsDuplicate[2]->id);
497
498
        $inputData['recommendsDuplicate'] = [
499
            [
500
                'recommendsDuplicate' => 1,
501
                'text' => 'I changed the recommend and the pivot text',
502
                'id' => 1,
503
            ],
504
            [
505
                'recommendsDuplicate' => 2,
506
                'text' => 'I changed the recommend and the pivot text 2',
507
                'id' => 2
508
            ],
509
            [
510
                'recommendsDuplicate' => 3,
511
                'text' => 'new recommend and the pivot text 3',
512
                'id' => null,
513
            ],
514
        ];
515
516
        $this->crudPanel->update($entry->id, $inputData);
517
        
518
        $entry = $entry->fresh();
519
   
520
        $this->assertCount(3, $entry->recommendsDuplicate);
521
        $this->assertDatabaseCount('recommendables', 3);
522
      
523
        $this->assertEquals('I changed the recommend and the pivot text', $entry->recommendsDuplicate[0]->pivot->text);
524
        $this->assertEquals('I changed the recommend and the pivot text 2', $entry->recommendsDuplicate[1]->pivot->text);
525
        $this->assertEquals('new recommend and the pivot text 3', $entry->recommendsDuplicate[2]->pivot->text);
526
527
    }
528
529
    public function testBelongsToManyWithPivotDataRelationship()
530
    {
531
        $this->crudPanel->setModel(User::class);
532
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
533
        $this->crudPanel->addField([
534
            'name' => 'superArticles',
535
            'subfields' => [
536
                [
537
                    'name' => 'notes',
538
                ],
539
            ],
540
        ]);
541
542
        $faker = Factory::create();
543
        $articleData = [
544
            'content' => $faker->text(),
545
            'tags' => $faker->words(3, true),
546
            'user_id' => 1,
547
        ];
548
549
        $article = Article::create($articleData);
550
551
        $inputData = [
552
            'name' => $faker->name,
553
            'email' => $faker->safeEmail,
554
            'password' => Hash::make($faker->password()),
555
            'remember_token' => null,
556
            'superArticles' => [
557
                [
558
                    'superArticles' => $article->id,
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
559
                    'notes' => 'my first article note',
560
                ],
561
            ],
562
        ];
563
564
        $entry = $this->crudPanel->create($inputData);
565
566
        $this->assertCount(1, $entry->fresh()->superArticles);
567
        $this->assertEquals('my first article note', $entry->fresh()->superArticles->first()->pivot->notes);
568
    }
569
570
    public function testBelongsToManyWithMultipleSameRelationIdAndPivotDataRelationship()
571
    {
572
        $inputData = $this->getPivotInputData(['superArticlesDuplicates' => [
573
            [
574
                'superArticlesDuplicates' => 1,
575
                'notes' => 'my first article note',
576
                'id' => null,
577
            ],
578
            [
579
                'superArticlesDuplicates' => 1,
580
                'notes' => 'my second article note',
581
                'id' => null,
582
            ],
583
            [
584
                'superArticlesDuplicates' => 2,
585
                'notes' => 'my first article2 note',
586
                'id' => null,
587
            ],
588
        ],
589
        ], true, true);
590
591
        $entry = $this->crudPanel->create($inputData);
592
        $relationField = $this->crudPanel->getUpdateFields($entry->id)['superArticlesDuplicates'];
593
594
        $this->assertCount(3, $relationField['value']);
595
596
        $entry = $entry->fresh();
597
598
        $this->assertCount(3, $entry->superArticlesDuplicates);
599
        $this->assertEquals('my first article note', $entry->superArticles->first()->pivot->notes);
0 ignored issues
show
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The method first() does not exist on BackedEnum. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

599
        $this->assertEquals('my first article note', $entry->superArticles->/** @scrutinizer ignore-call */ first()->pivot->notes);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property notes does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property notes does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property notes does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The method first() does not exist on UnitEnum. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

599
        $this->assertEquals('my first article note', $entry->superArticles->/** @scrutinizer ignore-call */ first()->pivot->notes);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property notes does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
Bug introduced by
The method first() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

599
        $this->assertEquals('my first article note', $entry->superArticles->/** @scrutinizer ignore-call */ first()->pivot->notes);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
600
        $this->assertEquals('my second article note', $entry->superArticles[1]->pivot->notes);
601
        $this->assertEquals('my first article2 note', $entry->superArticles[2]->pivot->notes);
602
603
        $inputData = $this->getPivotInputData(['superArticlesDuplicates' => [
604
            [
605
                'superArticlesDuplicates' => 1,
606
                'notes' => 'my first article note updated',
607
                'id' => 1,
608
            ],
609
            [
610
                'superArticlesDuplicates' => 1,
611
                'notes' => 'my second article note updated',
612
                'id' => 2,
613
            ],
614
            [
615
                'superArticlesDuplicates' => 2,
616
                'notes' => 'my first article2 note updated',
617
                'id' => 3,
618
            ],
619
        ],
620
        ], false, true);
621
622
        $entry = $this->crudPanel->update($entry->id, $inputData);
623
        $relationField = $this->crudPanel->getUpdateFields($entry->id)['superArticlesDuplicates'];
624
        $this->assertCount(3, $relationField['value']);
625
626
        $entry = $entry->fresh();
627
628
        $this->assertCount(3, $entry->superArticlesDuplicates);
629
        $this->assertEquals('my first article note updated', $entry->superArticles[0]->pivot->notes);
630
        $this->assertEquals('my second article note updated', $entry->superArticles[1]->pivot->notes);
631
        $this->assertEquals('my first article2 note updated', $entry->superArticles[2]->pivot->notes);
632
    }
633
634
    public function testBelongsToManyAlwaysSaveSinglePivotWhenMultipleNotAllowed()
635
    {
636
        $inputData = $this->getPivotInputData(['superArticlesDuplicates' => [
637
            [
638
                'superArticlesDuplicates' => 1,
639
                'notes' => 'my first article note',
640
                'id' => null,
641
            ],
642
            [
643
                'superArticlesDuplicates' => 1,
644
                'notes' => 'my second article note',
645
                'id' => null,
646
            ],
647
            [
648
                'superArticlesDuplicates' => 2,
649
                'notes' => 'my first article2 note',
650
                'id' => null,
651
            ],
652
        ],
653
        ]);
654
655
        $entry = $this->crudPanel->create($inputData);
656
        $relationField = $this->crudPanel->getUpdateFields($entry->id)['superArticlesDuplicates'];
657
658
        $this->assertCount(2, $relationField['value']);
659
660
        $entry = $entry->fresh();
661
662
        $this->assertCount(2, $entry->superArticlesDuplicates);
663
        $this->assertEquals('my second article note', $entry->superArticles[0]->pivot->notes);
664
        $this->assertEquals('my first article2 note', $entry->superArticles[1]->pivot->notes);
665
    }
666
667
    public function testBelongsToManyDeletesPivotData()
668
    {
669
        $inputData = $this->getPivotInputData(['superArticlesDuplicates' => [
670
            [
671
                'superArticlesDuplicates' => 1,
672
                'notes' => 'my first article note',
673
                'id' => null,
674
            ],
675
            [
676
                'superArticlesDuplicates' => 1,
677
                'notes' => 'my second article note',
678
                'id' => null,
679
            ],
680
            [
681
                'superArticlesDuplicates' => 2,
682
                'notes' => 'my first article2 note',
683
                'id' => null,
684
            ],
685
        ],
686
        ], true, true);
687
688
        $entry = $this->crudPanel->create($inputData);
689
        $relationField = $this->crudPanel->getUpdateFields($entry->id)['superArticlesDuplicates'];
690
691
        $this->assertCount(3, $relationField['value']);
692
693
        $inputData = $this->getPivotInputData(['superArticlesDuplicates' => [
694
            [
695
                'superArticlesDuplicates' => 1,
696
                'notes' => 'new first article note',
697
                'id' => null,
698
            ],
699
            [
700
                'superArticlesDuplicates' => 1,
701
                'notes' => 'my second article note updated',
702
                'id' => 2,
703
            ],
704
            [
705
                'superArticlesDuplicates' => 3,
706
                'notes' => 'my first article2 note updated',
707
                'id' => 3,
708
            ],
709
        ],
710
        ], false, true);
711
712
        $entry = $this->crudPanel->update($entry->id, $inputData);
713
        $relationField = $this->crudPanel->getUpdateFields($entry->id)['superArticlesDuplicates'];
714
        $this->assertCount(3, $relationField['value']);
715
716
        $entry = $entry->fresh();
717
718
        $this->assertCount(3, $entry->superArticlesDuplicates);
719
        $this->assertEquals('new first article note', $entry->superArticles[2]->pivot->notes);
720
        $this->assertEquals('my second article note updated', $entry->superArticles[0]->pivot->notes);
721
        $this->assertEquals('my first article2 note updated', $entry->superArticles[1]->pivot->notes);
722
    }
723
724
    public function testCreateHasOneWithNestedRelationsRepeatableInterface()
725
    {
726
        $this->crudPanel->setModel(User::class);
727
        $this->crudPanel->setOperation('create');
728
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
729
        $this->crudPanel->addField(
730
            [
731
                'name' => 'accountDetails',
732
                'subfields' => [
733
                    [
734
                        'name' => 'nickname',
735
                    ],
736
                    [
737
                        'name' => 'profile_picture',
738
                    ],
739
                    [
740
                        'name' => 'article',
741
                    ],
742
                    [
743
                        'name' => 'addresses',
744
                        'subfields' => [
745
                            [
746
                                'name' => 'bang',
747
                            ],
748
                            [
749
                                'name' => 'street',
750
                            ],
751
                            [
752
                                'name' => 'number',
753
                            ],
754
                        ],
755
                    ],
756
                    [
757
                        'name' => 'bangs',
758
                    ],
759
                    [
760
                        'name' => 'bangsPivot',
761
                        'subfields' => [
762
                            [
763
                                'name' => 'pivot_field',
764
                            ],
765
                        ],
766
                    ],
767
                ],
768
            ]);
769
770
        $faker = Factory::create();
771
772
        $inputData = [
773
            'name' => $faker->name,
774
            'email' => $faker->safeEmail,
775
            'password' => Hash::make($faker->password()),
776
            'remember_token' => null,
777
            'roles' => [1, 2],
778
            'accountDetails' => [
779
                [
780
                    'nickname' => 'i_have_has_one',
781
                    'profile_picture' => 'ohh my picture 1.jpg',
782
                    'article' => 1,
783
                    'addresses' => [
784
                        [
785
                            'bang' => 1,
786
                            'street' => 'test',
787
                            'number' => 1,
788
                        ],
789
                        [
790
                            'bang' => 1,
791
                            'street' => 'test2',
792
                            'number' => 2,
793
                        ],
794
                    ],
795
                    'bangs' => [1, 2],
796
                    'bangsPivot' => [
797
                        ['bangsPivot' => 1, 'pivot_field' => 'test1'],
798
                        ['bangsPivot' => 2, 'pivot_field' => 'test2'],
799
                    ],
800
                ],
801
            ],
802
        ];
803
804
        $entry = $this->crudPanel->create($inputData);
805
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
806
        $account_details = $entry->accountDetails()->first();
807
808
        $this->assertEquals($account_details->article, Article::find(1));
0 ignored issues
show
Bug introduced by
The property article does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property article does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
809
        $this->assertEquals($account_details->addresses->count(), 2);
0 ignored issues
show
Bug introduced by
The method count() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
        $this->assertEquals($account_details->addresses->/** @scrutinizer ignore-call */ count(), 2);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method count() does not exist on UnitEnum. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
        $this->assertEquals($account_details->addresses->/** @scrutinizer ignore-call */ count(), 2);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property addresses does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property addresses does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The method count() does not exist on BackedEnum. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
        $this->assertEquals($account_details->addresses->/** @scrutinizer ignore-call */ count(), 2);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
810
        $this->assertEquals($account_details->addresses->first()->city, 1);
0 ignored issues
show
Bug introduced by
The property city does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property city does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
811
        $this->assertEquals($account_details->addresses->first()->street, 'test');
0 ignored issues
show
Bug introduced by
The property street does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property street does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
812
        $this->assertEquals($account_details->addresses->first()->number, 1);
0 ignored issues
show
Bug introduced by
The property number does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property number does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
813
        $this->assertEquals($account_details->bangs->first()->name, Bang::find(1)->name);
0 ignored issues
show
Bug introduced by
The method first() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

813
        $this->assertEquals($account_details->bangs->/** @scrutinizer ignore-call */ first()->name, Bang::find(1)->name);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property bangs does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property bangs does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
814
        $this->assertEquals($account_details->bangsPivot->count(), 2);
0 ignored issues
show
Bug introduced by
The method count() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

814
        $this->assertEquals($account_details->bangsPivot->/** @scrutinizer ignore-call */ count(), 2);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property bangsPivot does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property bangsPivot does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
815
        $this->assertEquals($account_details->bangsPivot->first()->pivot->pivot_field, 'test1');
0 ignored issues
show
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
816
    }
817
818
    public function testCreateBelongsToFake()
819
    {
820
        $belongsToField = [   // select_grouped
821
            'label' => 'Select_grouped',
822
            'type' => 'select_grouped', //https://github.com/Laravel-Backpack/CRUD/issues/502
823
            'name' => 'bang_relation_field',
824
            'fake' => true,
825
            'entity' => 'bang',
826
            'model' => 'Backpack\CRUD\Tests\config\Models\Bang',
827
            'attribute' => 'title',
828
            'group_by' => 'category', // the relationship to entity you want to use for grouping
829
            'group_by_attribute' => 'name', // the attribute on related model, that you want shown
830
            'group_by_relationship_back' => 'articles', // relationship from related model back to this model
831
            'tab' => 'Selects',
832
            'wrapperAttributes' => ['class' => 'form-group col-md-6'],
833
        ];
834
835
        $this->crudPanel->setModel(User::class);
836
        $this->crudPanel->setOperation('create');
837
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
838
        $this->crudPanel->addField($belongsToField);
839
840
        $faker = Factory::create();
841
842
        $inputData = [
843
            'name' => $faker->name,
844
            'email' => $faker->safeEmail,
845
            'password' => Hash::make($faker->password()),
846
            'remember_token' => null,
847
            'bang_relation_field' => 1,
848
        ];
849
850
        $entry = $this->crudPanel->create($inputData);
851
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
852
        $this->crudPanel->entry = $entry->withFakes();
853
        $this->assertEquals($entry->bang_relation_field, 1);
854
    }
855
856
    public function testCreateHasOneWithNestedRelations()
857
    {
858
        $this->crudPanel->setModel(User::class);
859
        $this->crudPanel->setOperation('create');
860
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
861
        $this->crudPanel->addFields([
862
            [
863
                'name' => 'accountDetails.nickname',
864
            ],
865
            [
866
                'name' => 'accountDetails.profile_picture',
867
            ],
868
            [
869
                'name' => 'accountDetails.article',
870
            ],
871
            [
872
                'name' => 'accountDetails.addresses',
873
                'subfields' => [
874
                    [
875
                        'name' => 'city',
876
                        'entity' => 'bang',
877
                    ],
878
                    [
879
                        'name' => 'street',
880
                    ],
881
                    [
882
                        'name' => 'number',
883
                    ],
884
                ],
885
            ],
886
            [
887
                'name' => 'accountDetails.bangs',
888
            ],
889
            [
890
                'name' => 'accountDetails.bangsPivot',
891
                'subfields' => [
892
                    [
893
                        'name' => 'pivot_field',
894
                    ],
895
                ],
896
            ],
897
        ]);
898
899
        $faker = Factory::create();
900
901
        $inputData = [
902
            'name' => $faker->name,
903
            'email' => $faker->safeEmail,
904
            'password' => Hash::make($faker->password()),
905
            'remember_token' => null,
906
            'roles' => [1, 2],
907
            'accountDetails' => [
908
                'nickname' => 'i_have_has_one',
909
                'profile_picture' => 'ohh my picture 1.jpg',
910
                'article' => 1,
911
                'addresses' => [
912
                    [
913
                        'city' => 1,
914
                        'street' => 'test',
915
                        'number' => 1,
916
                    ],
917
                    [
918
                        'city' => 2,
919
                        'street' => 'test2',
920
                        'number' => 2,
921
                    ],
922
                ],
923
                'bangs' => [1, 2],
924
                'bangsPivot' => [
925
                    ['bangsPivot' => 1, 'pivot_field' => 'test1'],
926
                    ['bangsPivot' => 2, 'pivot_field' => 'test2'],
927
                ],
928
            ],
929
        ];
930
931
        $entry = $this->crudPanel->create($inputData);
932
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
933
        $account_details = $entry->accountDetails()->first();
934
935
        $this->assertEquals($account_details->article, Article::find(1));
0 ignored issues
show
Bug introduced by
The property article does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property article does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
936
        $this->assertEquals($account_details->addresses->count(), 2);
0 ignored issues
show
Bug introduced by
The property addresses does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property addresses does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
937
        $this->assertEquals($account_details->addresses->first()->bang->id, 1);
0 ignored issues
show
Bug introduced by
The property bang does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
Bug introduced by
The property bang does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
938
        $this->assertEquals($account_details->addresses->first()->street, 'test');
0 ignored issues
show
Bug introduced by
The property street does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property street does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
939
        $this->assertEquals($account_details->addresses->first()->number, 1);
0 ignored issues
show
Bug introduced by
The property number does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property number does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
940
        $this->assertEquals($account_details->bangs->first()->name, Bang::find(1)->name);
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property bangs does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property bangs does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
941
        $this->assertEquals($account_details->bangsPivot->count(), 2);
0 ignored issues
show
Bug introduced by
The property bangsPivot does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property bangsPivot does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
942
        $this->assertEquals($account_details->bangsPivot->first()->pivot->pivot_field, 'test1');
0 ignored issues
show
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property pivot does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property pivot_field does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
943
944
        // Now test the remove process
945
946
        $inputData = [
947
            'name' => $faker->name,
948
            'email' => $faker->safeEmail,
949
            'password' => Hash::make($faker->password()),
950
            'remember_token' => null,
951
            'roles' => [1, 2],
952
            'accountDetails' => [
953
                'nickname' => 'i_have_has_one',
954
                'profile_picture' => 'ohh my picture 1.jpg',
955
                'article' => 1,
956
                'addresses' => [ // HasOne is tested in other test function
957
                    [
958
                        'city' => 2,
959
                        'street' => 'test',
960
                        'number' => 1,
961
                    ],
962
                    [
963
                        'city' => 1,
964
                        'street' => 'test2',
965
                        'number' => 2,
966
                    ],
967
                ],
968
                'bangs' => [],
969
                'bangsPivot' => [],
970
            ],
971
        ];
972
973
        $entry = $this->crudPanel->update($entry->id, $inputData);
974
        $account_details = $entry->accountDetails()->first();
975
        $this->assertEquals($account_details->addresses->count(), 2);
976
        $this->assertEquals($account_details->addresses->first()->bang->id, 2);
977
        $this->assertEquals($account_details->bangs->count(), 0);
978
        $this->assertEquals($account_details->bangsPivot->count(), 0);
979
    }
980
981
    public function testMorphOneRelationship()
982
    {
983
        $this->crudPanel->setModel(User::class);
984
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

984
        $this->crudPanel->/** @scrutinizer ignore-call */ 
985
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
985
        $this->crudPanel->addField([
986
            'name' => 'comment.text',
987
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

987
        $this->crudPanel->/** @scrutinizer ignore-call */ 
988
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
988
989
        $faker = Factory::create();
990
        $inputData = [
991
            'name' => $faker->name,
992
            'email' => $faker->safeEmail,
993
            'password' => Hash::make($faker->password()),
994
            'remember_token' => null,
995
            'comment' => [
996
                'text' => 'some test comment text',
997
            ],
998
        ];
999
1000
        $entry = $this->crudPanel->create($inputData);
1001
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
1002
1003
        $this->assertEquals($inputData['comment']['text'], $entry->comment->text);
0 ignored issues
show
Bug introduced by
The property text does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property text does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
Bug introduced by
The property text does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
Bug introduced by
The property text does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
1004
1005
        $inputData['comment']['text'] = 'updated comment text';
1006
1007
        $this->crudPanel->update($entry->id, $inputData);
1008
1009
        $this->assertEquals($inputData['comment']['text'], $entry->fresh()->comment->text);
1010
    }
1011
1012
    public function testMorphManyCreatableRelationship()
1013
    {
1014
        $this->crudPanel->setModel(User::class);
1015
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1015
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1016
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1016
        $this->crudPanel->addField([
1017
            'name' => 'stars',
1018
            'subfields' => [
1019
                [
1020
                    'name' => 'title',
1021
                ],
1022
            ],
1023
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1023
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1024
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1024
1025
        $faker = Factory::create();
1026
        $inputData = [
1027
            'name' => $faker->name,
1028
            'email' => $faker->safeEmail,
1029
            'password' => Hash::make($faker->password()),
1030
            'remember_token' => null,
1031
            'stars' => [
1032
                [
1033
                    'id' => null,
1034
                    'title' => 'this is the star 1 title',
1035
                ],
1036
                [
1037
                    'id' => null,
1038
                    'title' => 'this is the star 2 title',
1039
                ],
1040
            ],
1041
        ];
1042
1043
        $entry = $this->crudPanel->create($inputData);
1044
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
1045
1046
        $this->assertCount(2, $entry->stars);
1047
1048
        $this->assertEquals($inputData['stars'][0]['title'], $entry->stars()->first()->title);
0 ignored issues
show
Bug introduced by
The property title does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property title does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
1049
1050
        $inputData['stars'] = [
1051
            [
1052
                'id' => 1,
1053
                'title' => 'only one star with changed title',
1054
            ],
1055
        ];
1056
1057
        $this->crudPanel->update($entry->id, $inputData);
1058
1059
        $this->assertCount(1, $entry->fresh()->stars);
1060
1061
        $this->assertEquals($inputData['stars'][0]['title'], $entry->fresh()->stars->first()->title);
1062
        $this->assertEquals($inputData['stars'][0]['id'], $entry->fresh()->stars->first()->id);
1063
    }
1064
1065
    public function testHasManyCreatableRelationship()
1066
    {
1067
        $this->crudPanel->setModel(User::class);
1068
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1068
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1069
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1069
        $this->crudPanel->addField([
1070
            'name' => 'universes',
1071
            'subfields' => [
1072
                [
1073
                    'name' => 'title',
1074
                ],
1075
            ],
1076
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1076
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1077
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1077
1078
        $faker = Factory::create();
1079
        $inputData = [
1080
            'name' => $faker->name,
1081
            'email' => $faker->safeEmail,
1082
            'password' => Hash::make($faker->password()),
1083
            'remember_token' => null,
1084
            'universes' => [
1085
                [
1086
                    'id' => null,
1087
                    'title' => 'this is the star 1 title',
1088
                ],
1089
                [
1090
                    'title' => 'this is the star 2 title',
1091
                ],
1092
            ],
1093
        ];
1094
1095
        $entry = $this->crudPanel->create($inputData);
1096
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
1097
1098
        $this->assertCount(2, $entry->universes);
1099
1100
        $this->assertEquals($inputData['universes'][0]['title'], $entry->universes()->first()->title);
0 ignored issues
show
Bug introduced by
The property title does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property title does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
1101
1102
        $inputData['universes'] = [
1103
            [
1104
                'id' => 1,
1105
                'title' => 'star 1 with changed title',
1106
            ],
1107
            [
1108
                'id' => 2,
1109
                'title' => 'star 2 with changed title',
1110
            ],
1111
        ];
1112
1113
        $this->crudPanel->update($entry->id, $inputData);
1114
1115
        $universes = $entry->fresh()->universes;
1116
        $this->assertCount(2, $universes);
1117
        $this->assertEquals([1, 2], $universes->pluck('id')->toArray());
1118
1119
        $inputData['universes'] = [
1120
            [
1121
                'id' => 1,
1122
                'title' => 'only one star with changed title',
1123
            ],
1124
        ];
1125
1126
        $this->crudPanel->update($entry->id, $inputData);
1127
1128
        $this->assertEquals($inputData['universes'][0]['title'], $entry->fresh()->universes->first()->title);
0 ignored issues
show
Bug introduced by
The method first() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1128
        $this->assertEquals($inputData['universes'][0]['title'], $entry->fresh()->universes->/** @scrutinizer ignore-call */ first()->title);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1129
        $this->assertEquals($inputData['universes'][0]['id'], $entry->fresh()->universes->first()->id);
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
1130
        $this->assertEquals(1, Universe::all()->count());
1131
1132
        $inputData['universes'] = [
1133
            [
1134
                'id' => null,
1135
                'title' => 'new star 3',
1136
            ],
1137
        ];
1138
1139
        $this->crudPanel->update($entry->id, $inputData);
1140
1141
        $this->assertEquals($inputData['universes'][0]['title'], $entry->fresh()->universes->first()->title);
1142
        $this->assertEquals(3, $entry->fresh()->universes->first()->id);
1143
        $this->assertEquals(1, Universe::all()->count());
1144
1145
        $inputData['universes'] = null;
1146
1147
        $this->crudPanel->update($entry->id, $inputData);
1148
1149
        $this->assertEquals(0, count($entry->fresh()->universes));
1150
        $this->assertEquals(0, Universe::all()->count());
1151
    }
1152
1153
    public function testHasManySelectableRelationshipWithoutForceDelete()
1154
    {
1155
        $this->crudPanel->setModel(User::class);
1156
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1156
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1157
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1157
        $this->crudPanel->addField([
1158
            'name' => 'planets',
1159
            'force_delete' => false,
1160
            'fallback_id' => false,
1161
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1161
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1162
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1162
1163
        $faker = Factory::create();
1164
        $inputData = [
1165
            'name' => $faker->name,
1166
            'email' => $faker->safeEmail,
1167
            'password' => Hash::make($faker->password()),
1168
            'remember_token' => null,
1169
            'planets' => [1, 2],
1170
        ];
1171
1172
        $entry = $this->crudPanel->create($inputData);
1173
        $updateFields = $this->crudPanel->getUpdateFields($entry->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $updateFields is dead and can be removed.
Loading history...
1174
1175
        $this->assertCount(2, $entry->planets);
1176
1177
        $inputData['planets'] = [1];
1178
1179
        $this->crudPanel->update($entry->id, $inputData);
1180
1181
        $this->assertCount(1, $entry->fresh()->planets);
1182
1183
        $planets = Planet::all();
1184
1185
        $this->assertCount(2, $planets);
1186
    }
1187
1188
    public function testHasManySelectableRelationshipRemoveAllRelations()
1189
    {
1190
        $this->crudPanel->setModel(User::class);
1191
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1191
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1192
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1192
        $this->crudPanel->addField([
1193
            'name' => 'planets',
1194
            'force_delete' => false,
1195
            'fallback_id' => false,
1196
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1196
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1197
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1197
1198
        $faker = Factory::create();
1199
        $inputData = [
1200
            'name' => $faker->name,
1201
            'email' => $faker->safeEmail,
1202
            'password' => Hash::make($faker->password()),
1203
            'remember_token' => null,
1204
            'planets' => [1, 2],
1205
        ];
1206
1207
        $entry = $this->crudPanel->create($inputData);
1208
1209
        $this->assertCount(2, $entry->planets);
1210
1211
        $inputData['planets'] = [];
1212
1213
        $this->crudPanel->update($entry->id, $inputData);
1214
1215
        $this->assertCount(0, $entry->fresh()->planets);
1216
1217
        $planets = Planet::all();
1218
1219
        $this->assertCount(2, $planets);
1220
    }
1221
1222
    public function testHasManyWithRelationScoped()
1223
    {
1224
        $this->crudPanel->setModel(User::class);
1225
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1225
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1226
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1226
        $this->crudPanel->addField([
1227
            'name' => 'incomes',
1228
            'subfields' => [
1229
                [
1230
                    'name' => 'label',
1231
                    'type' => 'text',
1232
                ],
1233
                [
1234
                    'name' => 'type',
1235
                    'type' => 'hidden',
1236
                    'value' => 'income',
1237
                ],
1238
                [
1239
                    'name' => 'amount',
1240
                    'type' => 'number',
1241
                ],
1242
            ],
1243
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1243
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1244
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1244
        $this->crudPanel->addField([
1245
            'name' => 'expenses',
1246
            'subfields' => [
1247
                [
1248
                    'name' => 'label',
1249
                    'type' => 'text',
1250
                ],
1251
                [
1252
                    'name' => 'type',
1253
                    'type' => 'hidden',
1254
                    'value' => 'expense',
1255
                ],
1256
                [
1257
                    'name' => 'amount',
1258
                    'type' => 'number',
1259
                ],
1260
            ],
1261
        ], 'both');
1262
1263
        $faker = Factory::create();
1264
        $inputData = [
1265
            'name' => $faker->name,
1266
            'email' => $faker->safeEmail,
1267
            'password' => Hash::make($faker->password()),
1268
            'remember_token' => null,
1269
            'incomes' => [
1270
                [
1271
                    'label' => $faker->name,
1272
                    'amount' => 33,
1273
                    'type' => 'income',
1274
                ],
1275
                [
1276
                    'label' => $faker->name,
1277
                    'amount' => 22,
1278
                    'type' => 'income',
1279
                ],
1280
            ],
1281
            'expenses' => [
1282
                [
1283
                    'label' => $faker->name,
1284
                    'amount' => 44,
1285
                    'type' => 'expense',
1286
                ],
1287
                [
1288
                    'label' => $faker->name,
1289
                    'amount' => 10,
1290
                    'type' => 'expense',
1291
                ],
1292
            ],
1293
        ];
1294
        $entry = $this->crudPanel->create($inputData);
1295
1296
        $firstExpense = $entry->expenses->first();
0 ignored issues
show
Bug introduced by
The method first() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1296
        /** @scrutinizer ignore-call */ 
1297
        $firstExpense = $entry->expenses->first();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
The assignment to $firstExpense is dead and can be removed.
Loading history...
1297
        $firstIncome = $entry->incomes->first();
0 ignored issues
show
Bug introduced by
The method first() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1297
        /** @scrutinizer ignore-call */ 
1298
        $firstIncome = $entry->incomes->first();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
The assignment to $firstIncome is dead and can be removed.
Loading history...
1298
        $this->assertCount(2, $entry->expenses);
1299
        $this->assertCount(2, $entry->incomes);
1300
        $this->assertEquals(44, $entry->expenses->first()->amount);
1301
        $this->assertEquals(33, $entry->incomes->first()->amount);
1302
1303
        $inputData['incomes'] = [
1304
            [
1305
                'id' => 2,
1306
                'label' => $faker->name,
1307
                'amount' => 222,
1308
                'type' => 'income',
1309
            ],
1310
        ];
1311
        $inputData['expenses'] = [
1312
            [
1313
                'id' => 3,
1314
                'label' => $faker->name,
1315
                'amount' => 44,
1316
                'type' => 'expense',
1317
            ],
1318
            [
1319
                'id' => 4,
1320
                'label' => $faker->name,
1321
                'amount' => 10,
1322
                'type' => 'expense',
1323
            ],
1324
        ];
1325
        $this->crudPanel->update($entry->id, $inputData);
1326
1327
        $freshIncomes = $entry->fresh()->incomes;
1328
        $freshExpenses = $entry->fresh()->expenses;
1329
        $this->assertCount(2, $freshExpenses);
1330
        $this->assertCount(1, $freshIncomes);
1331
        $this->assertEquals(2, $freshIncomes->first()->id);
1332
1333
        $inputData['expenses'] = [];
1334
        $this->crudPanel->update($entry->id, $inputData);
1335
1336
        $freshIncomes = $entry->fresh()->incomes;
1337
        $freshExpenses = $entry->fresh()->expenses;
1338
        $this->assertCount(0, $freshExpenses);
1339
        $this->assertCount(1, $freshIncomes);
1340
    }
1341
1342
    public function testHasManySelectableRelationshipWithFallbackId()
1343
    {
1344
        $this->crudPanel->setModel(User::class);
1345
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1345
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1346
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1346
        $this->crudPanel->addField([
1347
            'name' => 'planets',
1348
            'fallback_id' => 0,
1349
            'force_delete' => false,
1350
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1350
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1351
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1351
1352
        $faker = Factory::create();
1353
        $inputData = [
1354
            'name' => $faker->name,
1355
            'email' => $faker->safeEmail,
1356
            'password' => Hash::make($faker->password()),
1357
            'remember_token' => null,
1358
            'planets' => [1, 2],
1359
        ];
1360
1361
        $entry = $this->crudPanel->create($inputData);
1362
1363
        $this->assertCount(2, $entry->planets);
1364
1365
        $inputData['planets'] = [2];
1366
1367
        $this->crudPanel->update($entry->id, $inputData);
1368
1369
        $this->assertCount(1, $entry->fresh()->planets);
1370
1371
        $planets = Planet::all();
1372
        $this->assertCount(2, $planets);
1373
        $this->assertEquals(0, $planets->first()->user_id);
1374
    }
1375
1376
    public function testHasManySelectableRelationshipWithForceDelete()
1377
    {
1378
        $this->crudPanel->setModel(User::class);
1379
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1379
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1380
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1380
        $this->crudPanel->addField([
1381
            'name' => 'planets',
1382
            'force_delete' => true,
1383
            'fallback_id' => false,
1384
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1384
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1385
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1385
1386
        $faker = Factory::create();
1387
        $inputData = [
1388
            'name' => $faker->name,
1389
            'email' => $faker->safeEmail,
1390
            'password' => Hash::make($faker->password()),
1391
            'remember_token' => null,
1392
            'planets' => [1, 2],
1393
        ];
1394
1395
        $entry = $this->crudPanel->create($inputData);
1396
1397
        $this->assertCount(2, $entry->planets);
1398
1399
        $inputData['planets'] = [2];
1400
1401
        $this->crudPanel->update($entry->id, $inputData);
1402
1403
        $this->assertCount(1, $entry->fresh()->planets);
1404
1405
        $planets = Planet::all();
1406
        $this->assertCount(1, $planets);
1407
    }
1408
1409
    public function testHasManySelectableRelationshipNonNullableForeignKeyAndDefaultInDatabase()
1410
    {
1411
        $this->crudPanel->setModel(User::class);
1412
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1412
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1413
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1413
        $this->crudPanel->addField([
1414
            'name' => 'comets',
1415
            'force_delete' => false,
1416
            'fallback_id' => false,
1417
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1417
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1418
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1418
1419
        $faker = Factory::create();
1420
        $inputData = [
1421
            'name' => $faker->name,
1422
            'email' => $faker->safeEmail,
1423
            'password' => Hash::make($faker->password()),
1424
            'remember_token' => null,
1425
            'comets' => [1, 2],
1426
        ];
1427
1428
        $entry = $this->crudPanel->create($inputData);
1429
1430
        $this->assertCount(2, $entry->comets);
1431
1432
        $inputData['comets'] = [2];
1433
1434
        $this->crudPanel->update($entry->id, $inputData);
1435
1436
        $this->assertCount(1, $entry->fresh()->comets);
1437
1438
        $comets = Comet::all();
1439
        $this->assertCount(2, $comets);
1440
        $this->assertEquals(0, $comets->first()->user_id);
1441
    }
1442
1443
    public function testHasManySelectableRelationshipNonNullable()
1444
    {
1445
        $this->crudPanel->setModel(User::class);
1446
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1446
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1447
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1447
        $this->crudPanel->addField([
1448
            'name' => 'planetsNonNullable',
1449
            'force_delete' => false,
1450
            'fallback_id' => false,
1451
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1451
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1452
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1452
1453
        $faker = Factory::create();
1454
        $inputData = [
1455
            'name' => $faker->name,
1456
            'email' => $faker->safeEmail,
1457
            'password' => Hash::make($faker->password()),
1458
            'remember_token' => null,
1459
            'planetsNonNullable' => [1, 2],
1460
        ];
1461
1462
        $entry = $this->crudPanel->create($inputData);
1463
1464
        $this->assertCount(2, $entry->planetsNonNullable);
1465
1466
        $inputData['planetsNonNullable'] = null;
1467
1468
        $this->crudPanel->update($entry->id, $inputData);
1469
1470
        $this->assertCount(0, $entry->fresh()->planetsNonNullable);
1471
1472
        $planets = PlanetNonNullable::all();
1473
        $this->assertCount(0, $planets);
1474
    }
1475
1476
    public function testCreateHasManyRelationWithDelimitedNameSubfields()
1477
    {
1478
        $this->crudPanel->setModel(User::class);
1479
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...\CrudPanel::addFields() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1479
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1480
                          addFields($this->userInputFieldsNoRelationships, 'both');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1480
        $this->crudPanel->addField([
1481
            'name' => 'universes',
1482
            'subfields' => [
1483
                [
1484
                    'name' => 'title',
1485
                ],
1486
                [
1487
                    'name' => 'start_date,end_date',
1488
                    'type' => 'date_range',
1489
                ],
1490
            ],
1491
        ], 'both');
0 ignored issues
show
Unused Code introduced by
The call to Backpack\CRUD\app\Librar...l\CrudPanel::addField() has too many arguments starting with 'both'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1491
        $this->crudPanel->/** @scrutinizer ignore-call */ 
1492
                          addField([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1492
1493
        $faker = Factory::create();
1494
        $inputData = [
1495
            'name' => $faker->name,
1496
            'email' => $faker->safeEmail,
1497
            'password' => Hash::make($faker->password()),
1498
            'remember_token' => null,
1499
            'universes' => [
1500
                [
1501
                    'id' => null,
1502
                    'title' => 'this is the star 1 title',
1503
                    'start_date' => '2021-02-26',
1504
                    'end_date' => '2091-01-26',
1505
                ],
1506
                [
1507
                    'title' => 'this is the star 2 title',
1508
                    'end_date' => '2021-02-26',
1509
                    'start_date' => '2091-01-26',
1510
                ],
1511
            ],
1512
        ];
1513
1514
        $entry = $this->crudPanel->create($inputData);
1515
1516
        $this->assertCount(2, $entry->universes);
1517
1518
        $this->assertEquals($inputData['universes'][0]['start_date'], $entry->universes()->first()->start_date);
0 ignored issues
show
Bug introduced by
The property start_date does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property start_date does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
1519
        $this->assertEquals($inputData['universes'][0]['end_date'], $entry->universes()->first()->end_date);
0 ignored issues
show
Bug introduced by
The property end_date does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property end_date does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
1520
        $this->assertEquals($inputData['universes'][1]['end_date'], $entry->universes()->find(2)->end_date);
1521
        $this->assertEquals($inputData['universes'][1]['start_date'], $entry->universes()->find(2)->start_date);
1522
    }
1523
1524
    public function testCreateHasOneRelationWithDelimitedNameSubfields()
1525
    {
1526
        $this->crudPanel->setModel(User::class);
1527
        $this->crudPanel->setOperation('create');
1528
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
1529
        $this->crudPanel->addField(
1530
            [
1531
                'name' => 'accountDetails',
1532
                'subfields' => [
1533
                    [
1534
                        'name' => 'nickname',
1535
                    ],
1536
                    [
1537
                        'name' => 'start_date,end_date',
1538
                    ],
1539
                    [
1540
                        'name' => 'profile_picture',
1541
                    ],
1542
                ],
1543
            ]);
1544
1545
        $faker = Factory::create();
1546
1547
        $inputData = [
1548
            'name' => $faker->name,
1549
            'email' => $faker->safeEmail,
1550
            'password' => Hash::make($faker->password()),
1551
            'remember_token' => null,
1552
            'roles' => [1, 2],
1553
            'accountDetails' => [
1554
                [
1555
                    'nickname' => 'i_have_has_one',
1556
                    'profile_picture' => 'ohh my picture 1.jpg',
1557
                    'start_date' => '2021-02-26',
1558
                    'end_date' => '2091-01-26',
1559
                ],
1560
            ],
1561
        ];
1562
1563
        $entry = $this->crudPanel->create($inputData);
1564
        $account_details = $entry->accountDetails()->first();
1565
1566
        $this->assertEquals($account_details->start_date, '2021-02-26');
0 ignored issues
show
Bug introduced by
The property start_date does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
Bug introduced by
The property start_date does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
1567
        $this->assertEquals($account_details->end_date, '2091-01-26');
0 ignored issues
show
Bug introduced by
The property end_date does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property end_date does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
1568
    }
1569
1570
    public function testBelongsToManyWithDelimitedNameSubfields()
1571
    {
1572
        $this->crudPanel->setModel(User::class);
1573
        $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
1574
        $this->crudPanel->addField([
1575
            'name' => 'superArticles',
1576
            'subfields' => [
1577
                [
1578
                    'name' => 'notes',
1579
                ],
1580
                [
1581
                    'name' => 'start_date,end_date',
1582
                ],
1583
            ],
1584
        ]);
1585
1586
        $faker = Factory::create();
1587
        $articleData = [
1588
            'content' => $faker->text(),
1589
            'tags' => $faker->words(3, true),
1590
            'user_id' => 1,
1591
        ];
1592
1593
        $article = Article::create($articleData);
1594
1595
        $inputData = [
1596
            'name' => $faker->name,
1597
            'email' => $faker->safeEmail,
1598
            'password' => Hash::make($faker->password()),
1599
            'remember_token' => null,
1600
            'superArticles' => [
1601
                [
1602
                    'superArticles' => $article->id,
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
1603
                    'notes' => 'my first article note',
1604
                    'start_date' => '2021-02-26',
1605
                    'end_date' => '2091-01-26',
1606
                ],
1607
            ],
1608
        ];
1609
1610
        $entry = $this->crudPanel->create($inputData);
1611
1612
        $this->assertCount(1, $entry->fresh()->superArticles);
1613
        $superArticle = $entry->fresh()->superArticles->first();
1614
        $this->assertEquals($superArticle->pivot->start_date, '2021-02-26');
1615
        $this->assertEquals($superArticle->pivot->end_date, '2091-01-26');
1616
1617
        $this->crudPanel->getUpdateFields($superArticle->id);
1618
    }
1619
1620
    public function testItCanCreateMorphToFieldsStructure()
1621
    {
1622
        $this->crudPanel->setModel(Star::class);
1623
        $this->crudPanel->addField([
1624
            'name' => 'starable',
1625
            'morphOptions' => [
1626
                ['Backpack\CRUD\Tests\config\Models\User', 'User'],
1627
            ],
1628
        ]);
1629
1630
        $this->assertCount(2, $this->crudPanel->fields()['starable']['subfields']);
1631
1632
        [$morphTypeField, $morphIdField] = $this->crudPanel->fields()['starable']['subfields'];
1633
1634
        $this->assertTrue($morphTypeField['name'] === 'starable_type');
1635
        $this->assertTrue($morphIdField['name'] === 'starable_id');
1636
    }
1637
1638
    public function testIPreventsAddingRepeateadMorphOptions()
1639
    {
1640
        $this->crudPanel->setModel(Star::class);
1641
        $this->expectException(\Exception::class);
1642
1643
        $this->crudPanel->addField([
1644
            'name' => 'starable',
1645
            'morphOptions' => [
1646
                ['Backpack\CRUD\Tests\config\Models\User', 'User'],
1647
                ['Backpack\CRUD\Tests\config\Models\User', 'User'],
1648
            ],
1649
        ]);
1650
    }
1651
1652
    public function testItThrowsErrorIfStringIsNotOnMorphMap()
1653
    {
1654
        $this->crudPanel->setModel(Star::class);
1655
        $this->expectException(\Exception::class);
1656
1657
        $this->crudPanel->addField([
1658
            'name' => 'starable',
1659
            'morphOptions' => [
1660
                ['somethingThatDoesNotExist'],
1661
            ],
1662
        ]);
1663
    }
1664
1665
    public function testItCanAddTheOptionsFromTheMorphMap()
1666
    {
1667
        $this->crudPanel->setModel(Star::class);
1668
1669
        Relation::morphMap([
1670
            'user' => 'Backpack\CRUD\Tests\config\Models\User',
1671
        ]);
1672
1673
        $this->crudPanel->addField([
1674
            'name' => 'starable',
1675
            'morphOptions' => [
1676
                ['user'],
1677
            ],
1678
        ]);
1679
1680
        [$morphTypeField, $morphIdField] = $this->crudPanel->fields()['starable']['subfields'];
1681
        $this->assertEquals(['user' => 'Backpack\CRUD\Tests\config\Models\User'], $morphTypeField['morphMap']);
1682
    }
1683
1684
    public function testItThrowsErrorIfDuplicateMorphMapName()
1685
    {
1686
        $this->crudPanel->setModel(Star::class);
1687
        $this->expectException(\Exception::class);
1688
1689
        Relation::morphMap([
1690
            'user' => 'Backpack\CRUD\Tests\config\Models\User',
1691
        ]);
1692
1693
        $this->crudPanel->addField([
1694
            'name' => 'starable',
1695
            'morphOptions' => [
1696
                ['user'],
1697
                ['user'],
1698
            ],
1699
        ]);
1700
    }
1701
1702
    private function getPivotInputData(array $pivotRelationData, bool $initCrud = true, bool $allowDuplicates = false)
1703
    {
1704
        $faker = Factory::create();
1705
1706
        if ($initCrud) {
1707
            $this->crudPanel->setModel(User::class);
1708
            $this->crudPanel->addFields($this->userInputFieldsNoRelationships);
1709
            $this->crudPanel->addField([
1710
                'name' => array_key_first($pivotRelationData),
1711
                'allow_duplicate_pivots' => $allowDuplicates,
1712
                'pivot_key_name' => 'id',
1713
                'subfields' => [
1714
                    [
1715
                        'name' => 'notes',
1716
                    ],
1717
1718
                ],
1719
            ]);
1720
1721
            $article = Article::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $article is dead and can be removed.
Loading history...
1722
                'content' => $faker->text(),
1723
                'tags' => $faker->words(3, true),
1724
                'user_id' => 1,
1725
            ]);
1726
            $article2 = Article::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $article2 is dead and can be removed.
Loading history...
1727
                'content' => $faker->text(),
1728
                'tags' => $faker->words(3, true),
1729
                'user_id' => 1,
1730
            ]);
1731
        }
1732
1733
        $inputData = [
1734
            'name' => $faker->name,
1735
            'email' => $faker->safeEmail,
1736
            'password' => Hash::make($faker->password()),
1737
            'remember_token' => null,
1738
        ];
1739
1740
        return array_merge($inputData, $pivotRelationData);
1741
    }
1742
}
1743