P
P
photosho2016-02-22 12:35:25
Laravel
photosho, 2016-02-22 12:35:25

How to protect fields in Eloquent from editing?

Hello. There was such a question: how to protect fields from editing at the model level? That is, for example, a field username- can be added to the user during registration, but cannot be changed when editing the profile.
At the moment, I have implemented protection inside the controller responsible for saving the changes made - an array of names of fields prohibited for editing and an error call if one of the fields falls into this array. Perhaps this is the wrong way, and should this be done, nevertheless, at the model level?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Pochepko, 2016-02-22
@photosho

Tyk
There is an array guarded. Read about him

V
Victor, 2016-02-22
@v_decadence

Model properties guarded / fillable.
Documentation

V
Vyacheslav Plisko, 2016-02-22
@AmdY

You can create a setUsernameAttribute mutator and check for the existence of the entry there, throwing an exception in case of an error, so your model will always be in a valid state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question