Model :: create()雄辩的特定$ fillable和Model-> update()的另一个$ fillable

I need a way to set the ArticleCategory only on the creation of the Article model and does not changed through the update process using $fillable array. I need to do this with the following in the mind:

1- I want do this through mass assignment 2- I use form request validation for my validation

so is there $fillable array for create and one for update ?

Thanks ...

There is only one fillable property, so what you want is not possible by default.

But you can use only and just retrieve the inputs that you want to update:

From the docs:

If you need to retrieve a subset of the input data, you may use the only and except methods. Both of these methods accept a single array or a dynamic list of arguments:

$input = $request->only('username', 'password');

$input = $request->except(['credit_card']);

In your case it would be something like this:

public function update(UpdateArticleRequest $request, $id)
{
    $article = Article::findOrFail($id);
    $article->update($request->only('title', 'name'));
}

You can't really do that but you can consider the following alternative:

Do not put ArticleCategory in your $fillable array.

Use the following:

 $article = new Article($request->all());
 $article->ArticleCategory = $request->input('ArticleCategory');
 $article->save();

This way you are explicitly setting the article category when you need to and protecting it from mass assignment.

I think this would be the sensible way to tackle this as (from the sounds of it) ArticleCategory should be guarded in general.