# Getting Started
# Using Bagisto Package Generator
To facilitate package development, you can use the Bagisto Package Generator (opens new window). Follow the steps below to install it:
Install the Bagisto Package Generator by running the following command in the root folder of your Bagisto application:
composer require bagisto/bagisto-package-generator
Once installed, you can generate your package using the following command:
If the package directory does not exist:
php artisan package:make Webkul/Blog
If the package directory already exists, you can use the
--force
option to overwrite it:php artisan package:make Webkul/Blog --force
This command will set up the necessary files and directories in the
packages
directory.
# Registering Your Package
To register your package, follow these steps:
Add your package's namespace to the
psr-4
section in thecomposer.json
file located in the root directory of your Bagisto application. Update it as follows:"autoload": { ... "psr-4": { // Other PSR-4 namespaces "Webkul\\Blog\\": "packages/Webkul/Blog/src" } }
Register your package's service provider in the
config/app.php
file located in the root directory of your Bagisto application. Add the following line to theproviders
array:<?php return [ // Other configuration options 'providers' => ServiceProvider::defaultProviders()->merge([ // Other service providers Webkul\Blog\Providers\BlogServiceProvider::class, ])->toArray(), // Other configuration options ];
Run the following commands to autoload your package and publish its assets and configurations:
composer dump-autoload php artisan optimize php artisan vendor:publish --force
When prompted to select which items to publish, choose the number corresponding to
"Webkul\Blog\Providers\BlogServiceProvider"
and press enter to publish all assets and configurations.
Example Output in the Browser
Congratulations! Your package is now registered and ready to use. Start creating something cool!
# Manual Setup of Files
If you prefer to set up your package manually, follow these steps assuming you are familiar with package directory structures and workflows. We'll use the default package
folder in Bagisto as an example.
# Create Package Directory
Inside the
packages/Webkul
folder, create a folder with your package name. Your structure should look like this:└── packages └── Webkul └── Blog
In your package folder, create a folder named as
src
. This is where you'll put all your package-related files. Your updated structure will look like this:└── packages └── Webkul └── Blog └── src
# Create Service Provider
In the
src
folder, create a folder named asProviders
. Inside that folder, create a file named asBlogServiceProvider.php
. Your structure should look like this:└── packages └── Webkul └── Blog └── src └── Providers └── BlogServiceProvider.php
Copy the following code and paste it into
BlogServiceProvider.php
:<?php namespace Webkul\Blog\Providers; use Illuminate\Support\ServiceProvider; class BlogServiceProvider extends ServiceProvider { /** * Bootstrap services. * * @return void */ public function boot() { // } /** * Register services. * * @return void */ public function register() { // } }
# Register Your Package
Add your package's namespace to the
psr-4
section in thecomposer.json
file located in the root directory of your Bagisto application. Update it as follows:"autoload": { ... "psr-4": { // Other PSR-4 namespaces "Webkul\\Blog\\": "packages/Webkul/Blog/src" } }
Register your package's service provider in the
config/app.php
file located in the root directory of your Bagisto application. Add the following line to theproviders
array:<?php return [ // Other configuration options 'providers' => ServiceProvider::defaultProviders()->merge([ // Other service providers Webkul\Blog\Providers\BlogServiceProvider::class, ])->toArray(), // Other configuration options ];
Run the following command to autoload your package:
composer dump-autoload
Your package is now ready to use!