Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Illuminate/Database/Console/Factories/stubs/factory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace {{ factoryNamespace }};
use Illuminate\Database\Eloquent\Factories\Factory;
use {{ namespacedModel }};

/**
* @extends Factory<{{ model }}>
*/
class {{ factory }}Factory extends Factory
{
/**
Expand Down
19 changes: 11 additions & 8 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Illuminate\Support\Traits\Macroable;
use Throwable;

/**
* @template TDestinationModel of \Illuminate\Database\Eloquent\Model
*/
abstract class Factory
{
use ForwardsCalls, Macroable {
Expand All @@ -23,7 +26,7 @@ abstract class Factory
/**
* The name of the factory's corresponding model.
*
* @var string
* @var string|class-string<TDestinationModel>
*/
protected $model;

Expand Down Expand Up @@ -195,7 +198,7 @@ public function raw($attributes = [], ?Model $parent = null)
* Create a single model and persist it to the database.
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function createOne($attributes = [])
{
Expand All @@ -206,7 +209,7 @@ public function createOne($attributes = [])
* Create a single model and persist it to the database.
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function createOneQuietly($attributes = [])
{
Expand Down Expand Up @@ -246,7 +249,7 @@ public function createManyQuietly(iterable $records)
*
* @param array $attributes
* @param \Illuminate\Database\Eloquent\Model|null $parent
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function create($attributes = [], ?Model $parent = null)
{
Expand Down Expand Up @@ -274,7 +277,7 @@ public function create($attributes = [], ?Model $parent = null)
*
* @param array $attributes
* @param \Illuminate\Database\Eloquent\Model|null $parent
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function createQuietly($attributes = [], ?Model $parent = null)
{
Expand Down Expand Up @@ -335,7 +338,7 @@ protected function createChildren(Model $model)
* Make a single instance of the model.
*
* @param callable|array $attributes
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function makeOne($attributes = [])
{
Expand All @@ -347,7 +350,7 @@ public function makeOne($attributes = [])
*
* @param array $attributes
* @param \Illuminate\Database\Eloquent\Model|null $parent
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function make($attributes = [], ?Model $parent = null)
{
Expand Down Expand Up @@ -657,7 +660,7 @@ protected function newInstance(array $arguments = [])
* Get a new model instance.
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model|TDestinationModel
*/
public function newModel(array $attributes = [])
{
Expand Down