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。。。

  • 相关阅读:
    Vue(小案例_vue+axios仿手机app)_go实现退回上一个路由
    nyoj 635 Oh, my goddess
    nyoj 587 blockhouses
    nyoj 483 Nightmare
    nyoj 592 spiral grid
    nyoj 927 The partial sum problem
    nyoj 523 亡命逃窜
    nyoj 929 密码宝盒
    nyoj 999 师傅又被妖怪抓走了
    nyoj 293 Sticks
  • 原文地址:https://www.cnblogs.com/qwgshare/p/6023600.html
Copyright © 2011-2022 走看看