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(); To create … Read more

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 … 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. In Laravel, the default database type can be changed by modifying the configuration settings in the … Read more

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 … 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. To implement a package in Laravel, you can follow these steps: Choose or … Read more