search
HomePHP FrameworkLaravelLaravel extension package development steps [Summary]

The following tutorial column will summarize the laravel expansion package development steps for you. I hope it will be helpful to friends who need it!

Laravel extension package development steps [Summary]##1. Create package

 php artisan workbench vendor/package --resources
Note: vendor: developer name package: package name

2. Modify the authors

in composer.json in the package

"authors": [
    {
        "name": "cicl",
        "email": "test@126.com"
    }
]
3. Register the created packageServiceProvider

##Execute php artisan dump-autoload# in the project root directory

##Add the package to the providers array in the app/config/app.php file and add Vendor\Package\PackageServiceProvider to the providers array.<span style="font-family:'Microsoft Yahei';font-size:medium;"></span>

In order to facilitate our use, we add an alias in the aliases of app/config/app.php: <span style="font-family:'Microsoft Yahei';font-size:medium;"></span>'Package' => 'Vendor \Package\Facades\Notification',

Start the development server: php artisan serve, if it is started successfully, as shown: Laravel development server started on http://localhost:8000<span style="font-family:'Microsoft Yahei';font-size:medium;"> , then the basic construction of the expansion package is successful. </span>

Basic extension package structure:

        /src
            /Vendor
                /Package
                    PackageServiceProvider.php
            /config
            /lang
            /migrations
            /views
        /tests
        /public
4. To add an independent routing file to this package, just add it in the boot function in PackageServiceProvider Add the following code and create the routes.php file in the root directory of the package


public function boot(){    
    $this->package('vendor/package');    
    include __DIR__.'/../../routes.php';
}

The routing file looks like this:

Route::get('test',  function(){    return "this is test";});
Now, in Enter the address in the browser such as: http://localhost:8000/test, and "this is test" will be output.

5. Next try to use Controller

Create a new route as follows:

Route::get('testtwo',array('as' => 'testtwo','uses' => 'Vendor\Package\Controllers\PackageController@getTest'));
6, Create a new RegistrationController.php file in controllers. The code is as follows:

<?php namespace Ccl\Lenon\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;

Class LenonController extends Controller {
     public function getTest() {
         return "控制器测试";
     }
}
When I try to open the page, it says that the controller cannot be found. Laravel does not automatically search for any directories by default. The developer needs to do this himself. Specify the storage directory of the file, but it also gives a recommended path. For example, when using artisan workbench, is the src/controllers directory generated? Ok, we can just add the automatic loading path.

7. Add "src/controllers" to the classmap field under autoload of composer.json in the root directory of the package,

such as:

 "classmap": [
       "src/migrations",
       "src/controllers"
],
And run php artisan dump-autoload in the project root directory and refresh the page. 8. Next we have to use the views file! According to our understanding, we only need to modify the code in the controller, as follows:

public function getRegister()    
{  
    return View::make('test'); 
}

Create the test.blade.php file under the package src/views/ and write in the file Related page code, for example:

This is the file of the test view

Refresh the page and find that it is not successful. In Laravel, the package will not be automatically indexed. view file, so we still need to do a little work!

9. When loading the view, specify it to look for the view file in the package. Modify the code in the controller as follows:

public function getRegister()    
{ 
    return View::make('package::test');    
}
Refresh the page again, and the page we are looking forward to appears,

public migration

php artisan asset:publish --bench="vendor/package"

Create database migration

php artisan migrate:make create_users_table --bench="vendor/package"

执行数据库迁移

php artisan migrate --bench="vendor/package"

The above is the detailed content of Laravel extension package development steps [Summary]. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:cnblogs. If there is any infringement, please contact admin@php.cn delete
Using Laravel: Streamlining Web Development with PHPUsing Laravel: Streamlining Web Development with PHPApr 19, 2025 am 12:18 AM

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

Laravel: An Introduction to the PHP Web FrameworkLaravel: An Introduction to the PHP Web FrameworkApr 19, 2025 am 12:15 AM

Laravel is a modern PHP framework that provides a powerful tool set, simplifies development processes and improves maintainability and scalability of code. 1) EloquentORM simplifies database operations; 2) Blade template engine makes front-end development intuitive; 3) Artisan command line tools improve development efficiency; 4) Performance optimization includes using EagerLoading, caching mechanism, following MVC architecture, queue processing and writing test cases.

Laravel: MVC Architecture and Best PracticesLaravel: MVC Architecture and Best PracticesApr 19, 2025 am 12:13 AM

Laravel's MVC architecture improves the structure and maintainability of the code through models, views, and controllers for separation of data logic, presentation and business processing. 1) The model processes data, 2) The view is responsible for display, 3) The controller processes user input and business logic. This architecture allows developers to focus on business logic and avoid falling into the quagmire of code.

Laravel: Key Features and Advantages ExplainedLaravel: Key Features and Advantages ExplainedApr 19, 2025 am 12:12 AM

Laravel is a PHP framework based on MVC architecture, with concise syntax, powerful command line tools, convenient data operation and flexible template engine. 1. Elegant syntax and easy-to-use API make development quick and easy to use. 2. Artisan command line tool simplifies code generation and database management. 3.EloquentORM makes data operation intuitive and simple. 4. The Blade template engine supports advanced view logic.

Building Backend with Laravel: A GuideBuilding Backend with Laravel: A GuideApr 19, 2025 am 12:02 AM

Laravel is suitable for building backend services because it provides elegant syntax, rich functionality and strong community support. 1) Laravel is based on the MVC architecture, simplifying the development process. 2) It contains EloquentORM, optimizes database operations. 3) Laravel's ecosystem provides tools such as Artisan, Blade and routing systems to improve development efficiency.

Laravel framework skills sharingLaravel framework skills sharingApr 18, 2025 pm 01:12 PM

In this era of continuous technological advancement, mastering advanced frameworks is crucial for modern programmers. This article will help you improve your development skills by sharing little-known techniques in the Laravel framework. Known for its elegant syntax and a wide range of features, this article will dig into its powerful features and provide practical tips and tricks to help you create efficient and maintainable web applications.

The difference between laravel and thinkphpThe difference between laravel and thinkphpApr 18, 2025 pm 01:09 PM

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

Laravel user login function listLaravel user login function listApr 18, 2025 pm 01:06 PM

Building user login capabilities in Laravel is a crucial task and this article will provide a comprehensive overview covering every critical step from user registration to login verification. We will dive into the power of Laravel’s built-in verification capabilities and guide you through customizing and extending the login process to suit specific needs. By following these step-by-step instructions, you can create a secure and reliable login system that provides a seamless access experience for users of your Laravel application.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor