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,490 points
5,425 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,680 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,680 points
189 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,680 points
1,596 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,680 points
614 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,680 points
232 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,680 points
362 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,680 points
342 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,680 points
172 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,680 points
166 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,680 points
7,911 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,680 points
344 views