濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)

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

熱門(mén)標(biāo)簽:熱線(xiàn)電話(huà)機(jī)器人 福泉電話(huà)機(jī)器人 太原極信防封電銷(xiāo)卡 格陵蘭島地圖標(biāo)注 電銷(xiāo)招聘機(jī)器人 地圖標(biāo)注入哪個(gè)科目 事業(yè)單位如何百度地圖標(biāo)注 南寧crm外呼系統(tǒng)平臺(tái) 天津營(yíng)銷(xiāo)電話(huà)機(jī)器人加盟代理

一,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)證不通過(guò)
        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)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Laravel基礎(chǔ)_關(guān)于view共享數(shù)據(jù)的示例講解
  • laravel框架模型、視圖與控制器簡(jiǎn)單操作示例
  • laravel通過(guò)a標(biāo)簽從視圖向控制器實(shí)現(xiàn)傳值
  • Laravel5.5 視圖 - 創(chuàng)建視圖和數(shù)據(jù)傳遞示例

標(biāo)簽:阿克蘇 佳木斯 自貢 通化 金華 郴州 香港 寶雞

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)》,本文關(guān)鍵詞  laravel,根據(jù),不同,組織,加載,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    海林市| 武定县| 保德县| 青州市| 长沙县| 东莞市| 分宜县| 北宁市| 乐东| 曲靖市| 滕州市| 潜山县| 化德县| 大化| 锦州市| 喜德县| 横峰县| 民和| 武川县| 巴林左旗| 锡林郭勒盟| 同仁县| 搜索| 舒兰市| 高尔夫| 景宁| 普兰县| 论坛| 黄龙县| 麦盖提县| 股票| 蒲城县| 那曲县| 浮梁县| 法库县| 鲜城| 南昌市| 云南省| 天祝| 浠水县| 锦屏县|