Laravel Interview Questions | Eklavya Online

Laravel Interview Questions

How will you explain Guarded Attribute in a Laravel model?

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 …

How will you explain Guarded Attribute in a Laravel model? Read More »

How will you describe Fillable Attribute in a Laravel model?

In eloquent ORM, $fillable attribute is an array containing all those fields of table which can be filled using mass-assignment. Mass assignment refers to sending an array to the model to directly create a new record in Database. Code Source class User extends Model { protected $fillable = [‘name’, ’email’, ‘mobile’]; // All fields inside …

How will you describe Fillable Attribute in a Laravel model? Read More »

How can we create a record in Laravel using eloquent?

We need to create a new model instance if we want to create a new record in the database using Laravel eloquent. Then we are required to set attributes on the model and call the save() method. Example public functionsaveProduct(Request $request ) $product = new product; $product->name = $request->name; $product->description = $request->name; $product->save();

How can we use maintenance mode in Laravel 5?

When an application is in maintenance mode, a custom view is displayed for all requests into the application. It makes it easy to “disable” application while it is updating or performing maintenance. A maintenance mode check is added in the default middleware stack for our application. When an application is in maintenance mode, a MaintenanceModeException …

How can we use maintenance mode in Laravel 5? Read More »

How can someone change the default database type in Laravel?

Laravel is configured to use MySQL by default. To change its default database type, edit the file config/database.php: Search for ‘default’ =>env(‘DB_CONNECTION’, ‘mysql’) Change it to whatever required like ‘default’ =>env(‘DB_CONNECTION’, ‘sqlite’) By using it, MySQL changes to SQLite.

What do you know about Traits in Laravel?

PHP Traits is a group of methods which can be included within another class. A Trait cannot be instantiated by itself like an abstract class. Traits are generated to reduce the limitations of single inheritance in PHP. It allows a developer to reuse sets of methods freely in various independent classes living in different class …

What do you know about Traits in Laravel? Read More »

How can we implement a package in Laravel?

We can implement a package in Laravel by: Creating a package folder and name it. Creating Composer.json file for the package. Loading package through main composer.json and PSR-4. Creating a Service Provider. Creating a Controller for the package. Creating a Routes.php file.