zoukankan      html  css  js  c++  java
  • 关于laravel5.2仓库的建立,以及简单调用

    laravel个人比较喜欢,就是控制器里面逻辑代码的分离,这样结构很清晰,有利于后期的维护,现在就把平时工作中运用的仓库模式,分享一下,望指正。

    ***********************************************************
    门面里这样写:

    app/Facades/QinFacade.php

    <?php
    namespace AppFacades;
    use IlluminateSupportFacadesFacade;
    class QinFacade extends Facade{
        protected static function getFacadeAccessor(){
            return 'QinRepository';
        }
    } 

    ************************************************************

    服务提供者里这样写:
    app/Providers/QinServiceProvider.php

    <?php
    
    namespace AppProviders;
    
    use IlluminateSupportServiceProvider;
    
    class QinServiceProvider extends ServiceProvider
    {
    /**
    * Bootstrap the application services.
    *
    * @return void
    */
    public function boot()
    {
    //
    }
    
    /**
    * Register the application services.
    *
    * @return void
    */
    public function register()
    {
        $this->app->singleton('QinRepository', function($app){
                return new AppRepositoriesadminQinRepository();
            });
        }
    }    

    *****************************************************************
    Repositories里这样写:
    app/Repositories/admin/QinRepository.php

    <?php
    
    namespace AppRepositoriesadmin;
    
    class QinRepository{
    
        public function show_test(){
            return 'this is my first success !!!';
        }
        public function index(){
            return '你是我的小丫小苹果,怎么爱你都不嫌多!';
        }
    }

    ******************************************************************
    config里这样写:
    config/app.php

    'providers' => [
    AppProvidersQinServiceProvider::class,
    ],
    
    'aliases' => [
    'Qin' => AppFacadesQinFacade::class,
    ],

    ******************************************************************
    控制器使用
    use Qin
    方法中使用
    Qin::index();
    Qin::show_test();
    *******************************************************************

    怎么越看越挫的感觉ing。。。

  • 相关阅读:
    106. Construct Binary Tree from Inorder and Postorder Traversal
    105. Construct Binary Tree from Preorder and Inorder Traversal
    449. Serialize and Deserialize BST
    114. Flatten Binary Tree to Linked List
    199. Binary Tree Right Side View
    173. Binary Search Tree Iterator
    98. Validate Binary Search Tree
    965. Univalued Binary Tree
    589. N-ary Tree Preorder Traversal
    eclipse设置总结
  • 原文地址:https://www.cnblogs.com/qwgshare/p/6023600.html
Copyright © 2011-2022 走看看