That is correct.
I however, like I stated prefer using validation to determine what should be inserted.
Take this for example:
$validData = $request->validate([
'title' => 'required',
'body' => 'required',
]);
Post::create($validData);
The $validData array will only contain the title and the body, so even if I pass in id, it will not get inserted in the table.
Here is another example using a form request class, and foreign keys.
We start with the controller.
public function __invoke(MovieFormRequest $request)
{
Movie::create($request->validated());
return redirect(route('movies.index'));
}
And the Form request
class MovieFormRequest extends FormRequest
{
public function rules(): array
{
return [
'title' => ['required', 'string'],
'release_year' => [
'required',
'numeric',
'min_digits:4',
'max_digits:4',
'between:1800,'.Carbon::now()->addYear(1)->year,
],
'blurb' => ['required', 'string', new MinWords(3)],
'runtime' => ['required', 'numeric', 'min_digits:2', 'max_digits:3', 'between:1,999'],
'actor' => ['required', 'array'],
'genre_id' => ['required', 'exists:genres,id'],
'format_id' => ['required', 'exists:format,id'],
];
}
}