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!
##1. Create package
php artisan workbench vendor/package --resources
2. Modify the authors
in composer.json in the package
"authors": [ { "name": "cicl", "email": "test@126.com" } ]
##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>
/src
/Vendor
/Package
PackageServiceProvider.php
/config
/lang
/migrations
/views
/tests
/public
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";});
5. Next try to use Controller
Create a new route as follows:Route::get('testtwo',array('as' => 'testtwo','uses' => 'Vendor\Package\Controllers\PackageController@getTest'));
<?php namespace Ccl\Lenon\Controllers; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\View; Class LenonController extends Controller { public function getTest() { return "控制器测试"; } }
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" ],
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:
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'); }
public migration
php artisan asset:publish --bench="vendor/package"
Create database migrationphp 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!