• 关于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。。。

  • 相关阅读:
    产品方法论
    elastic search语句
    计算机科学发展的动力
    理论计算机科学学习网站
    算法学习 howto
    人工智能和机器学习 AI&ML howto
    Deep Learning 和 Knowledge Graph howto
    LISP语言学习资源
    Turing Year 2012
    如何做好计算机科学研究
  • 原文地址:https://www.cnblogs.com/qwgshare/p/6023600.html
Copyright © 2020-2023  润新知