Git Product home page Git Product logo

setup-laravel5-package's Introduction

Laravel 5 package Development from scratch

Trying to explain Laravel specific package development in Laravel 5 ๐Ÿ‘

With the new Laravel 5 - php artisan workbench is made redundant. And technically Laravel packages should not be tightly coupled with Laravel core, so that make sense.

But for some who wants to build Laravel specific packages I suppose this will help them to have a quick start.

Step 1 : Install Laravel

http://laravel.com/docs/5.0#install-laravel

Note : In my above root i haven't added a .env file. You need to configure this.
Note : Laravel may require some permissions to be configured: folders within storage and vendor require write access by the web server.

Step 2 : Create package folder and service provider

In root directory create a folder called packages/vendorName/packageName/src e.g. root/packages/jai/Contact/src

Now navigate to the src folder and create a file for your service provider, e.g. ContactServiceprovider.php.

Your service provider should extend ServiceProvider and has to implement the register method.

Please look into this file for an example.

If you want you can write dd("testing"); in the boot function and go to step 3, but if you have copied the service provider file you might want to create views, routes, config and controllers.

Creating Routes

In your src folder create a new Http folder in which you create your routes.php file. (example file)

Creating Controllers

In your Http folder create a new directory called Controllers. In this folder you can create your controllers. (example file)

Creating Config

In your src folder create a new directory and call it config. In it create a new file (e.g. contact.php) like this file

Note: if you want to access config - you need to publish first - after doing step 5 you can run php artisan vendor:publish. This will push you config file (contact.php => project/config/contact.php) and then you can access config.

Creating Views

This is a bit different, in your package folder (e.g. jai/Contact) create a new folder call views. (example file 1 example file 2)

Step 3: Add package path in root composer.json

In your root composer.json file "jai\\Contact\\": "packages/jai/Contact/src/" under psr-4

    "psr-4": {
        "App\\": "app/",
        "Jai\\Contact\\": "packages/jai/contact/src/",
    }

Step 4: add service provider in app conifg.

In your root/config/app.php under providers add your package service provider to hook your package in.

        'Jai\Contact\ContactServiceProvider',

Step 5: loading your package

run composer dump-autoload - make sure there are no errors.

all done - now you can access your package via url - "yourwebsite/contact"

Check out Included test Branch for how we can Write test in Laravel Package.

DO share this repository if you liked it.

UPDATE :

New Branch added : Where Basic Tests are Included.

setup-laravel5-package's People

Contributors

ikkentim avatar jaiwalker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.