How to set makovye relations in Laravel?

0 like 0 dislike
8 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 | 8 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,186 answers
0 comments
33,921 users