How to set makovye relations in Laravel?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
16 views
Deal with tests in Laravel, faced with the problem:
There is a model (model 1) - it's easy to substitute an instance of the factory
But this model has a hasMany-relation (model 2), it would also need to replace the

As such it is possible to organize?
by | 16 views

1 Answer

0 like 0 dislike
class AlbumTest extends TestCase { use DatabaseMigrations; public function test() { $album = factory('Album')->create(); $songs = new Collection([ factory('Song')->make(['duration' => 291]), factory('Song')->make(['duration' => 123]), factory('Song')->make(['duration' => 100]), ]); $album->songs()->saveMany($songs); } }
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users