Best practice for modular programming in Laravel 5+

I am starting a new project, and I want to reuse some parts of it, mainly material related to user registration and authentication. I can copy and paste all the code, but I want to use it again. I know what Laravel has Package Development, but it is not easy and it seems that there should be a better way. A few days ago I find pingpong/modules, but I do not know about it. This is a third-party plugin and do not trust it.

Is using this plugin true? Is this plugin updated later? What is the difference Embedd Package Laraveland pingpong/modules? or do you have any suggestions?

+4
source share
3 answers

Pingpong modules it seems to be built for an earlier version of Laravel 5 and how compatible they are with future versions (and maybe with the current 5.1.11), I can’t say.

Not much activity can be seen in the commit history for 2.1, today (December 18) the last commit was more than 6 months ago.

But is the package specifically designed for Laravel? It seems. They offer many features useful for development. The only bad thing: you get a lot of code in your own environment git(is this good? I don’t know what you prefer).

Personally, I don’t like this for development, I prefer them in the vendor/ folder , otherwise it hurts me to update it to a newer version.

Laravel 5 Taylor , Laravel 4. , ( ), Laravel, ServiceProvider s. ServiceProvider - Laravel.

, ( github/packagist Satis).

Pingpong (2.1) Laravel 5, (Embedded Laravel Package) Laravel 4, , .

?

, / , Asgard CMS. , , , ( ).

?

, . , . modules , / . .

, app/, Laravel , CMS/API.

:

tests/
src/
    Acme/
        Controllers/
        Requests/
    Models/
        Module.php // contains some specifc calculations for example
    ModelServiceProvider.php
composer.json

composer.json : "Module\\": "src/" config/app.php ModuleServiceProvider. Laravel app().

, Models , , composer . :

<?php 

    require_once __DIR__ .'/vendor/autoload.php';

    use Module\Models\Module;

    $module = new Module;

, , API CMS:

tests/
src/
    Cms/
        Controllers/
        Requests/
    Api/
        Controllers/
        Transformers/
    Models/
        Module.php // contains some specifc calculations for example
    Providers/
        CmsServiceProvider.php // includes `ModuleServiceProvider`
        ApiServiceProvider.php // includes `ModuleServiceProvider`
    ModuleServiceProvider.php // contains global stuff like commands etc.
composer.json

ModuleServiceProvider config/app.php ApiServiceProvider CmsServiceProvider /.

+1

, php namespaces use, .

  

namespace Acme\Tools;
class Foo
{
 echo "me";
}

foo

<?php 

$foo = new \Acme\Tools\Foo();

.

use, :

<?php
use \Acme\Tools\Foo;
$foo = new Foo();

, , .. Auth middle-ware, , , . http://laravel.com/docs/5.1/middleware

Eloquent ORM REST apis , , Illuminate\Database\Eloquent\Model;, :

use Illuminate\Database\Eloquent\Model;. http://laravel.com/docs/5.1/eloquent

Laravel Laravel In built Helper, ,

+1

pingpong. . , . . , , , + . . , . jimmy, , .

In the figure below you will see an example of pingpong modules. As you, this is pretty much the same structure as the application folder. Perhaps a larger root folder. Usually it starts start.php, and you have a route.php int file http folder. I tuned mine a bit. Download front-end and back-end routes to RouteServiceProvider. It is built with laravel 5.1.

enter image description here

0
source

Source: https://habr.com/ru/post/1619191/


All Articles