最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)

 更新時(shí)間:2019年10月14日 18:02:16   作者:路上的影子  
今天小編就為大家分享一篇laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

一,controller 層定義helper.php 文件

定義全局常量

public function __construct()
{
  $this->middleware(function ($request, $next) {
    $this->_user = Auth::user();
    //全局的數(shù)據(jù)處理,所有視圖共用 
    $this->_beforeActionInit();
    if ($this->_user) {
      define('ORG_ID', $this->_user->organization_id);
      $this->_currentOrganization = Organization::find(ORG_ID);
    } else {
      define('ORG_ID', 0);
    }
    
    View::share('user', $this->_user);
    View::share('currentOrganization', $this->_currentOrganization);
    return $next($request);
  });
}




/** * 獲取對(duì)應(yīng)視圖 */if (!function_exists('get_organization_view')) { /** * @param $flag * @return \Illuminate\Config\Repository|mixed */ function get_organization_view($flag, $org_id = 1) { $view = config("view.$flag." . $org_id); if (empty($view)) { throw new RuntimeException('Orgnization Error'); } return $view; }}


//二, config 下定義view.php
return [
  'register' => [
    1 => 'register.1',
    2 => 'register.2'
  ]
]
// 三,sercive 層定義UserService.php
public function getValidateRule($org_id)
{
 
    $rule = [//驗(yàn)證必填項(xiàng),確認(rèn)密碼和密碼要相同
      'userName' => 'required|alpha_num|size:6|regex:/^[a-zA-Z]{3}[0-9]{2}[a-zA-Z]{1}$/',
      'password' => 'required|min:6',
      'confirmPassword' => 'required|same:password',
    ];
  
  return $rule;
}

四,view下定義視圖

register文件夾下有

1.blade.php,

2.blade.php

//五,controller下引用

/**
 * 注冊(cè)
 */
public function register(Request $request)
{
  
    //提交注冊(cè)
    if ($request->isMethod('post')) {
      $credentials = $request->only(['userName', 'password', 'confirmPassword']);//表單提交數(shù)據(jù)
      $rules = UserService::make($location->organization_id)->getValidateRule($location->organization_id);
      $validator = Validator::make($credentials, $rules);
      if ($validator->fails()) {//驗(yàn)證不通過
        return Redirect::back()->withInput()->withErrors($validator);
      }
      $exists = User::where('name', $credentials['userName'])->first();
      if ($exists) {
        $result = Lang::has("register.userExists") ? trans("register.userExists") : "User exists";
        return $this->_remind('error', $result, 'register');
      }
      $user = new User();
      $user->name = trim($credentials['userName']);
      $user->password = bcrypt($credentials['password']);
      if ($user->save()) {
        //注冊(cè)成功
        return redirect('/login')->with('msg', Lang::has("register.success") ? trans("register.success") : 'Register Success.');
      } else {
        //注冊(cè)失敗
        $validator->errors()->add('other', $user);//如果注冊(cè)失敗會(huì)把錯(cuò)誤原因返回
        return Redirect::back()->withInput()->withErrors($validator);
      }
    }
    return view(get_organization_view('register',$organization_id), ["location" => $location->name]);//加載視圖
  } catch (\Exception $ex){
    $this->_remind('error', $ex->getMessage(),'getActivationCode');
  }
}

以上這篇laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

祥云县| 曲阜市| 天镇县| 黄冈市| 巍山| 陵水| 沙湾县| 清水河县| 运城市| 镶黄旗| 紫云| 兴和县| 福贡县| 云霄县| 九江县| 宜兰市| 旬邑县| 南部县| 鄂托克旗| 和平区| 电白县| 梅州市| 荆州市| 甘肃省| 武夷山市| 伊宁市| 海口市| 辛集市| 准格尔旗| 罗甸县| 齐齐哈尔市| 当雄县| 邮箱| 杭锦旗| 南京市| 溧水县| 彭泽县| 栾川县| 淳化县| 马尔康县| 囊谦县|