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 in Laravel by kartik
• 10,990 points
138 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 by Niroj
• 22,110 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 in Laravel by Niroj
• 22,110 points
32 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 in Laravel by Niroj
• 22,110 points
108 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 in Laravel by Niroj
• 22,110 points
39 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 in Laravel by Niroj
• 22,110 points
38 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 in Laravel by Niroj
• 22,110 points
67 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 in Laravel by Niroj
• 22,110 points
62 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 in Laravel by Niroj
• 22,110 points
32 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 in Laravel by Niroj
• 22,110 points
28 views
0 votes
1 answer

Describe Fillable Attribute in a Laravel model?

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

answered Mar 27 in Laravel by Niroj
• 22,110 points
176 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 in Laravel by Niroj
• 22,110 points
33 views