Package Development for Laravel & PHP
Learn to build your own reusable packages for open source or profitable projects.
4.46 (45 reviews)

150
students
2 hours
content
Sep 2022
last update
$19.99
regular price
Why take this course?
Based on the detailed outline provided, here's a step-by-step guide on how to create a Laravel package from scratch, including all the necessary components such as autoloading, facades, service providers, testing, routing, controllers, views, configurations, models and migrations, assets, code coverage, publishing on Packagist, semantic versioning, README file, and licensing.
Introduction & What is a Package
- Understanding Packages: Explain the concept of packages in Laravel and the benefits of using them.
- Prerequisites: Ensure you have Composer, Git, and PHPUnit installed.
Creating your first package
- Setting up the Directory: Create a new directory for your package and set it up with Composer.
- Creating a Basic Structure: Define the basic structure of your package (
src
,tests
,resources
,config
, etc.). - Writing Package Code: Write a simple class that provides functionality which can be used by other applications.
How to autoload classes in your packages
- PSR-4 Autoloading: Configure Composer's autoloader using PSR-4 to automatically load your package classes.
Facades, Service Container & Service Providers explained
- Service Container: Understand how Laravel's service container works and how it can be used to bind classes and singletons.
- Service Providers: Create a service provider for your package, which will register services with the application on boot.
- Facades: Create facade classes and files, and configure them in your service provider.
How to add Package Auto-Discovery in Laravel
- ServiceProvider Registration: Register your service provider so that it is automatically discovered by Laravel.
- Facade Discovery: Use the
php artisan vendor:publish --provider='YourPackageServiceProvider'
command to publish facades.
How to test your packages
- Testing Basics: Configure PHPUnit in your package's
composer.json
file. - Writing Tests: Write tests for your package, following the same practices as you would in a Laravel application.
How to add routes to packages
- Defining Routes: Write route definitions that can be loaded by applications using your package.
How to add controllers to your package
- Creating Controllers: Implement controllers within your package and use them without namespaces in the application.
How to add views to your packages
- Loading Views: Configure view paths within your package so that they can be loaded with namespaces.
- Overwritable Views: Allow the end user to publish the views for modification.
How to allow configuration in your packages
- Configuration Files: Provide a default configuration file for your package.
- Publishable Configurations: Use
php artisan vendor:publish
to make the configurations editable by the end user.
How to add Models and Migrations to your packages
- Providing Migrations: Create migration files for your package's database tables.
- Making Migrations Publishable: Allow the end user to publish and modify migrations.
How to allow to modify Migrations in your packages
- Migration Versioning: Handle version control for migrations to avoid conflicts when modifying.
How to add translations to your packages
- Localization: Provide language files for internationalization support.
- Publishable Language Files: Use
php artisan vendor:publish
to allow the end user to override default languages.
How to use Git & Github to publish on Packagist
- Initializing a Repository: Initialize your package's directory with Git.
- Pushing to Github: Push your code to a new repository on Github.
- Publishing on Packagist: Add your package to Packagist, which requires approval based on semantic versioning.
How to add Semantic versioning to your packages
- Understanding Semantic Versioning (SemVer): Adopt the SemVer specification for versioning your package.
What is the README file for
- Creating a README: Write a comprehensive README file that explains what your package does, how to install it, and how to use it.
How to choose a License
- Selecting a License: Decide on a license that suits your project's needs and include the license in your package.
By following this guide, you will have a comprehensive understanding of how to create a Laravel package, from its initial setup to its final publication on Packagist. This will enable you to share your code with the community and contribute to the ecosystem of Laravel applications.
Loading charts...
Related Topics
4582982
udemy ID
06/03/2022
course created date
17/04/2022
course indexed date
Bot
course submited by