Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Alternate implementation to allow "safe" objects to be used by Eloquent models (without breaking mass assignment protection) #50218

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Typehint for forceCreate in MorphMany
  • Loading branch information
x7ryan committed Feb 23, 2024
commit 7ebbd131e3fb194c4c10dd13b9320f7d2bc75d5a
9 changes: 5 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/MorphMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ValidatedInput;

class MorphMany extends MorphOneOrMany
{
Expand Down Expand Up @@ -67,10 +68,10 @@ public function match(array $models, Collection $results, $relation)
/**
* Create a new instance of the related model. Allow mass-assignment.
*
* @param array|\Illuminate\Support\ValidatedInput $attributes
* @param array|ValidatedInput $attributes
* @return \Illuminate\Database\Eloquent\Model
*/
public function forceCreate($attributes = [])
public function forceCreate(array|ValidatedInput $attributes = [])
{
$attributes[$this->getMorphType()] = $this->morphClass;

Expand All @@ -80,10 +81,10 @@ public function forceCreate($attributes = [])
/**
* Create a new instance of the related model with mass assignment without raising model events.
*
* @param array|\Illuminate\Support\ValidatedInput $attributes
* @param array|ValidatedInput $attributes
* @return \Illuminate\Database\Eloquent\Model
*/
public function forceCreateQuietly($attributes = [])
public function forceCreateQuietly(array|ValidatedInput $attributes = [])
{
return Model::withoutEvents(fn () => $this->forceCreate($attributes));
}
Expand Down
Loading