Create a Directory for the Package
Navigate to the Project Root: Open your terminal and go to your Laravel project directory.
cd /path/to/your/project
Create a packages
Directory: This directory will hold your custom packages.
mkdir packages
Add the Package Code: Inside the packages
directory, create the necessary folder structure for the w3speedster
package:
mkdir -p packages/w3speedster/w3speedster
Configure the Package in Composer
Open the composer.json
File: This file is located in the root directory of your Laravel project. You can open it in any code editor (e.g., VS Code, Sublime Text).
Add the Repository Configuration: Add the following snippet to the repositories
section of your composer.json
file. If the repositories
section does not exist, create it at the root level of the JSON structure:
"repositories":[
{
"type":"path",
"url":"packages/w3speedster/w3speedster"
}
]
- type: Indicates that this is a package located in your local filesystem.
- url: Specifies the path to the package directory.
Save the Changes: Once you’ve added the configuration, save the file.
Install the Package
Now, run the following commands in your terminal to install and set up the package:
Require the Package:
composer require w3speedster/w3speedster:1.0.0
This command tells Composer to install the package from the specified path. It will handle dependencies and autoload the package into your project.
Run the Package Installer:
php artisan w3speedster:install
This Artisan command will set up the package within your Laravel application, performing tasks such as:
- Publishing configuration files.
- Running migrations (if applicable).
- Any other setup tasks defined by the package.
Verification and Final Steps
Confirm Installation:
- Check the composer.json file under the require section to ensure w3speedster/w3speedster is listed.
- Verify that the package files have been autoloaded by Composer (you may find them under vendor/composer/autoload_*).
Test the Installation:
- Ensure that the package’s functionality is accessible.
- Refer to the package’s documentation or run php artisan to see if the package’s commands are registered.
Clear and Cache Configurations (Optional):
- Clear the application cache to avoid conflicts:
php artisan cache:clear
- Refresh the Composer autoload files:
composer dump-autoload