quinta-feira, 14 de março de 2024

Laravel create service

 php artisan create service

To create a service in Laravel using the artisan command, you can use the laravel-service-generator package. Here’s how to install and use it:

  1. Install the package using Composer:
composer require timwassenburg/laravel-service-generator --dev
  1. After installation, the php artisan make:service command will be available in the list of artisan commands.

  2. To generate a new service, use the following artisan command:

php artisan make:service YourServiceName

This will create an empty service class in the app\Services directory.

  1. Optionally, you can add multiple method names (separated by a comma) with the --methods parameter. For example:
php artisan make:service YourServiceName --methods=method1,method2
  1. You can also generate a service for a model by adding the --service or -S parameter. For example:
php artisan make:controller PostController --service
  1. To generate a service, migration, seeder, factory, policy, and resource controller for the model, use the -a or --all parameter. For example:
php artisan make:model User -a

This will generate a service, migration, seeder, factory, policy, and resource controller for the User model.

Remember to import the generated service class and use it in your application as needed.

Nenhum comentário:

Postar um comentário