Explain Guarded Attribute in a Laravel model

0 votes
Is Guarded attribute is same as fillable attribute in Laravel? Explain about it?

Thank you
Mar 27, 2020 in Laravel by kartik
• 37,520 points
34,908 views

1 answer to this question.

0 votes

Hii,

The guarded attribute is the opposite of fillable attributes.

In Laravel, fillable attributes are used to specify those fields which are to be mass assigned. Guarded attributes are used to specify those fields which are not mass assignable.

Code Source

                            class User extends Model {  

                            protected $guarded = ['role'];   

                            // All fields inside the $guarded array are not mass-assignable  

                            }  

If we want to block all the fields from being mass-assigned, we can use:

  1. protected $guarded = ['*'];  

$fillable serves as a "white list" whereas $guarded functions serves like a "black list". One should use either $fillable or $guarded.

Thank You!!

answered Mar 27, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

Explain the concept of encryption and decryption in Laravel?

It is a process of transforming any ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,297 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,880 points
6,494 views
0 votes
1 answer

Explain make Method in Laravel and what does the make() method do in Laravel?

Hey, You may use the make method to ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,880 points
5,154 views
0 votes
1 answer

How can we create a record in Laravel using eloquent?

We need to create a new model ...READ MORE

answered Mar 20, 2020 in Laravel by Niroj
• 82,880 points
1,189 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,650 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,409 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,196 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
989 views
0 votes
2 answers

Describe Fillable Attribute in a Laravel model?

Hello @kartik In eloquent ORM, $fillable attribute is ...READ MORE

answered Mar 27, 2020 in Laravel by Niroj
• 82,880 points
41,259 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
2,371 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP