ringechchen vor 5 Jahren
Ursprung
Commit
7162767fe5

+ 9
- 0
.gitignore Datei anzeigen

@@ -0,0 +1,9 @@
1
+/node_modules
2
+/public/storage
3
+/public/hot
4
+/storage/*.key
5
+/vendor
6
+/.idea
7
+Homestead.json
8
+Homestead.yaml
9
+.env.*

+ 3
- 1
documents/deployments/readMeFirst.md Datei anzeigen

@@ -62,6 +62,8 @@ ogilvy.runtime.environment=dev
62 62
 error_log = /tmp/php_errors.log
63 63
 ```
64 64
 
65
+service apache2 restart # 重啟 Apache 使剛才的設定生效
66
+
65 67
 ### PRE/PRO環境背景與環境建置
66 68
 1. 由於這些環境背景與建置方式取決於專案或客戶,所以不另行介紹,預設參考 DEV 環境。
67 69
 
@@ -165,7 +167,7 @@ vi /etc/apache2/sites-available/ringeProject.conf # 創建專案的 apache 配
165 167
 a2ensite ringeProject # 啟動該配置文件
166 168
 
167 169
 service apache2 reload # 重載入 Apache 使剛才的設定生效
168
-改成
170
+
169 171
 接著編輯自己的操作電腦(並非 Ubuntu 那台),編輯它的 host 文件(舉例 windows 系統放在 C:\Windows\System32\drivers\etc\hosts),於文件末端加入一行
170 172
 
171 173
 ```

+ 96
- 0
documents/samples/readMeFirst.md Datei anzeigen

@@ -0,0 +1,96 @@
1
+# 開發範例相關
2
+
3
+## 後台欄目列表增刪查改
4
+
5
+### A. 前置作業
6
+組內開發同事需要先行定義有功能的名稱與程式中的命名空間,例如:
7
+
8
+上層選單中文名稱: 動物園管理
9
+上層選單英文名稱: zooManagement
10
+下層選單中文名稱: 老虎管理
11
+下層選單英文名稱: tigerManagement
12
+
13
+因此整個範例的命名如下(或參照後續介紹):
14
+
15
+1. 下層選單路由: 上層選單英文名稱/下層選單英文名稱
16
+2. 資料表名稱: 上層選單英文名稱_下層選單英文名稱
17
+
18
+需要先以瀏覽器登入後台
19
+
20
+System ManagementManage Functions > Add >
21
+
22
+1. Menu Icon Class Name: fa fa-cog
23
+2. Menu Name: 動物園管理
24
+3. Valid: 打勾
25
+4. Orders: 任意給一個數字
26
+
27
+System ManagementManage Functions > 動物園管理 > Details > Add >
28
+
29
+1. Function Name: 老虎管理
30
+2. Function Link(Route or Controller Name): zooManagement/tigerManagement
31
+3. Function Description: 任意給定一個敘述
32
+4. Valid: 打勾
33
+5. Orders: 任意給一個數字
34
+
35
+System ManagementManage Groups > 選定自己所屬群組(或新增) > Edit >
36
+
37
+1. Functions > Unassign > 選擇老虎管理 > 按下 Enter > 老虎管理落入 Assigned
38
+
39
+### B. 資料表
40
+先利用 phpmyadmin 或者開發環境的指令介面創建範例資料表,注意命名規則:
41
+
42
+```
43
+CREATE TABLE `ringeProject`.`zooManagement_tigerManagement` (
44
+	`id` INT(10) NOT NULL AUTO_INCREMENT COMMENT '自增量' ,
45
+	`tigerName` VARCHAR(16) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '老虎名字',
46
+	PRIMARY KEY (`id`)
47
+)
48
+ENGINE = MyISAM
49
+CHARSET = utf8 COLLATE utf8_unicode_ci
50
+COMMENT = '動物園管理_老虎管理';
51
+```
52
+
53
+創建 model 檔案,請參照 app/Models/ZooManagement/TigerManagement.php 這隻檔案
54
+
55
+### C. 實際開發
56
+需要因此新增或修改的檔案如下(請注意命名方式):
57
+
58
+1. 新增 app/Models/ZooManagement/TigerManagement.php 也就是剛才提到的 model
59
+2. 修改 routes/web.php 需要加入相關的路由,注意裡面註解的範例部分,負責路由
60
+3. 新增 app/Http/Controllers/Backend/ZooManagement/TigerManagementController.php 注意裡面的所有註解,負責控制器
61
+4. 新增 app/Http/Services/Backend/ZooManagement/TigerManagementService.php 注意裡面的所有註解,負責業務邏輯
62
+5. 新增 resources/views/admin/ZooManagement/TigerManagement.blade.php 注意裡面的所有註解,負責列表頁
63
+6. 新增 resources/views/admin/ZooManagement/TigerManagementEdit.blade.php 注意裡面的所有註解,負責新增或編輯頁
64
+
65
+### D. 注意事項
66
+
67
+1. 網址路由中的大小寫,可能會因為佈署環境的關係(例如 Windows 系統)導致大小寫被視為相同而失效,屆時的調整方向可以從伺服器作業系統設定,或者修改本地程式碼入手。
68
+
69
+## 腳本
70
+
71
+### A. 實際開發
72
+需要因此新增或修改的檔案如下(請注意命名方式):
73
+
74
+1. 修改 app/Console/Kernel.php 需要加入相關的路由,注意裡面註解的範例部分,負責路由
75
+2. 新增 app/Console/Commands/Lion.php 負責腳本本身
76
+
77
+### B. 除錯
78
+請確認已做好佈署文件中的除錯設定,並且視情況修改以下的指令並執行
79
+
80
+cd /var/www/html/ringeProject # 切換到專案資料夾
81
+
82
+export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=127.0.0.1 remote_port=7900" # 設置除錯變量
83
+
84
+export PHP_IDE_CONFIG="serverName=ringeProject" # 設置除錯變量
85
+
86
+php artisan zoo:lion # 啟動腳本
87
+
88
+### C. 佈署
89
+crontab -e # 編輯排程表加入以下指令(並視情況修改執行時間點,專案資料夾,重導向紀錄內容的位置)
90
+
91
+```
92
+* * * * * cd /var/www/html/ringeProject;php artisan zoo:lion > /tmp/test.log;
93
+```
94
+
95
+/etc/init.d/cron restart # 重啟排程服務
96
+

+ 18
- 0
sampleProject/.env Datei anzeigen

@@ -0,0 +1,18 @@
1
+APP_ENV=dev                                                 # 本範例用在開發環境上所以指定為 dev ,但實際情況會用在預設的線上環境需要指定 pro
2
+APP_KEY=base64:MtT8zoZvIJxglLOMY75wXScbK3rRcxPMHYQoiIvaGRQ= # 在下過 php artisan key:generate 指令後,此行會更新,需要同步到所有相關設定檔
3
+APP_DEBUG=true                                              # dev 環境建議開啟,pro 環境建議關閉
4
+APP_LOG_LEVEL=debug                                         # dev 環境建議指定 debug ,pro 環境建議指定 info
5
+APP_URL=http://ringeProject.ogilvy.com.tw                   # 建議使用 xxx.ogilvy.com.tw 的命名方式(另有教學會指定讓該網址生效),避免開發環境太多臨時專案都用 localhost 產生衝突
6
+APP_NAME=ringeProject                                       # 可填寫程式資料夾的名字,不會被網頁的任何地方顯示
7
+
8
+DB_CONNECTION=mysql                                         # 此行基本上不需要改,用 mysql/maria 都適用
9
+DB_HOST=127.0.0.1                                           # 若按照教學進行則可指定本機,不然可視當前環境另外指定
10
+DB_PORT=3306                                                # mysql 預設的 port 可不用修改
11
+DB_DATABASE=ringeProject                                    # 指定連接的資料庫名稱,可視環境修改
12
+DB_USERNAME=root                                            # mysql 帳號
13
+DB_PASSWORD=root                                            # mysql 密碼
14
+
15
+BROADCAST_DRIVER=log                                        # 不需修改或視情況修改
16
+CACHE_DRIVER=file                                           # 不需修改或視情況修改
17
+SESSION_DRIVER=file                                         # 不需修改或視情況修改
18
+QUEUE_DRIVER=sync                                           # 不需修改或視情況修改

+ 1
- 1
sampleProject/.gitignore Datei anzeigen

@@ -6,4 +6,4 @@
6 6
 /.idea
7 7
 Homestead.json
8 8
 Homestead.yaml
9
-.env
9
+.env.*

+ 26
- 0
sampleProject/app/Console/Commands/Lion.php Datei anzeigen

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace App\Console\Commands;
4
+
5
+use Illuminate\Console\Command;
6
+
7
+class Lion extends Command
8
+{
9
+    
10
+    protected $signature   = 'zoo:lion';
11
+    protected $description = 'lion eat tiger';
12
+    
13
+    public function __construct()
14
+    {
15
+        parent::__construct();
16
+    }
17
+    
18
+    /**
19
+     * 脚本入口
20
+     */
21
+    public function handle()
22
+    {
23
+        echo "I am Lion\n";
24
+    }
25
+    
26
+}

+ 2
- 1
sampleProject/app/Console/Kernel.php Datei anzeigen

@@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel
13 13
      * @var array
14 14
      */
15 15
     protected $commands = [
16
-        //
16
+        // 腳本入口
17
+        Commands\Lion::class,
17 18
     ];
18 19
 
19 20
     /**

+ 19
- 24
sampleProject/app/Http/Controllers/Backend/UsersController.php Datei anzeigen

@@ -15,67 +15,62 @@ class UsersController extends Controller
15 15
     public function index()
16 16
     {
17 17
         $tables = User::all();
18
-
18
+        
19 19
         return view('admin.users', [
20 20
             'tables' => $tables,
21 21
         ]);
22 22
     }
23
-
23
+    
24 24
     public function create(Request $request)
25 25
     {
26
-        return view('admin.usersedit',[
26
+        return view('admin.usersedit', [
27 27
             'operdata' => "",
28 28
         ]);
29 29
     }
30
-
30
+    
31 31
     public function edit($id)
32 32
     {
33 33
         $usr_id = $id;
34 34
         $operdata = User::find($usr_id);
35
-
36
-        return view('admin.usersedit',[
35
+        
36
+        return view('admin.usersedit', [
37 37
             'operdata' => $operdata,
38 38
         ]);
39 39
     }
40
-
40
+    
41 41
     public function store(Request $request)
42 42
     {
43
-        $role = \App\Role::where('name', 'admin')->first();
44
-
45
-        if ($request->mode == "insert")
46
-        {
43
+        //$role = \App\Role::where('name', 'admin')->first();
44
+        
45
+        if ($request->mode == "insert") {
47 46
             $user = new User;
48 47
             $user->name = $request->name;
49 48
             $user->email = $request->email;
50 49
             $user->password = bcrypt($request->password);
51 50
             $user->save();
52
-            $user->attachRole($role);
51
+            
52
+            //$user->attachRole($role);
53 53
             return redirect('/backend/Users');
54
-        }
55
-        else
56
-        {
54
+        } else {
57 55
             $user = User::find($request->id);
58 56
             $user->name = $request->name;
59
-            if ($request->password != "")
60
-            {
57
+            if ($request->password != "") {
61 58
                 $user->password = bcrypt($request->password);
62 59
             }
63 60
             $user->save();
64
-
61
+            
65 62
             return redirect('/backend/Users');
66 63
         }
67 64
     }
68
-
65
+    
69 66
     public function delete(Request $request, User $id)
70 67
     {
71
-        if($id->email == "admin@gmail.com")
72
-        {
68
+        if ($id->email == "admin@gmail.com") {
73 69
             return Redirect::back()->withErrors("Administrator can not be delete!");
74
-        }
75
-        else
76
-        {
70
+        } else {
77 71
             $id->delete();
78 72
         }
73
+        
79 74
         return Redirect::back();
80 75
     }
81 76
 }

+ 116
- 0
sampleProject/app/Http/Controllers/Backend/ZooManagement/TigerManagementController.php Datei anzeigen

@@ -0,0 +1,116 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Backend\ZooManagement;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Http\Services\Backend\ZooManagement\TigerManagementService;
7
+use App\Http\Controllers\Controller;
8
+
9
+class TigerManagementController extends Controller
10
+{
11
+    
12
+    // 相關私有服務層調用器宣告
13
+    private $tigerManagementSv;
14
+    
15
+    public function __construct()
16
+    {
17
+        // 建構服務層調用器
18
+        $this->tigerManagementSv = new TigerManagementService();
19
+    }
20
+    
21
+    /**
22
+     * 列表頁
23
+     *   本端點非 API,於 controller 取列表值後,存於變量渲染到 view
24
+     *   排序、分頁均未實現
25
+     * @return array:          返回渲染頁
26
+     */
27
+    public function index()
28
+    {
29
+        // 取得參數與驗證
30
+        // 服務層取得資料(以及實現各種業務上的邏輯)
31
+        $tigers = $this->tigerManagementSv->getTigers();
32
+        
33
+        // 渲染
34
+        return view('admin.ZooManagement.TigerManagement', [
35
+            'operdata' => $tigers,
36
+        ]);
37
+    }
38
+    
39
+    /**
40
+     * 新增老虎頁面
41
+     *   本端點非 API,直接到 view
42
+     * @return array:          返回渲染頁
43
+     */
44
+    public function create()
45
+    {
46
+        // 渲染
47
+        return view('admin.ZooManagement.TigerManagementEdit', [
48
+            'operdata' => "",
49
+        ]);
50
+    }
51
+    
52
+    /**
53
+     * 編輯老虎頁面
54
+     *   本端點非 API,依照變量取得資料後,渲染到 view
55
+     *
56
+     * @param  integer $id :    老虎的自增量
57
+     *
58
+     * @return array:          返回渲染頁
59
+     */
60
+    public function edit($id)
61
+    {
62
+        // 取得參數與驗證
63
+        // 服務層取得資料(以及實現各種業務上的邏輯)
64
+        $tiger = $this->tigerManagementSv->getTigerById($id);
65
+        
66
+        // 渲染
67
+        return view('admin.ZooManagement.TigerManagementEdit', [
68
+            'operdata' => $tiger,
69
+        ]);
70
+    }
71
+    
72
+    /**
73
+     * 新增或編輯老虎的端點
74
+     *   本端點非 API,依照參數新增或修改資料後,跳轉到既有的 view
75
+     *
76
+     * @param  Request $request :  整包參數
77
+     *
78
+     * @return array:             返回跳轉渲染頁的資訊
79
+     */
80
+    public function store(Request $request)
81
+    {
82
+        // 取得參數與驗證
83
+        $mode = $request->mode;
84
+        $id = ($request->mode == 'insert') ? '' : $request->id;
85
+        $tigerName = $request->tigerName;
86
+        // 服務層設置(以及實現各種業務上的邏輯)
87
+        if ($mode == "insert") {
88
+            // 新增模式
89
+            $this->tigerManagementSv->insertTiger($tigerName);
90
+        } else {
91
+            // 編輯模式
92
+            $this->tigerManagementSv->modifyTiger($id, $tigerName);
93
+        }
94
+        
95
+        // 跳轉
96
+        return redirect('/backend/zooManagement/tigerManagement');
97
+    }
98
+    
99
+    /**
100
+     * 刪除老虎的端點
101
+     *   本端點非 API,依照參數刪除資料後,跳轉到既有的 view
102
+     *
103
+     * @param  integer $id :    老虎的自增量
104
+     *
105
+     * @return array:           返回跳轉渲染頁的資訊
106
+     */
107
+    public function delete($id)
108
+    {
109
+        // 取得參數與驗證
110
+        // 服務層取得資料(以及實現各種業務上的邏輯)
111
+        $this->tigerManagementSv->deleteTigerById($id);
112
+    
113
+        // 跳轉
114
+        return Redirect::back();
115
+    }
116
+}

+ 1
- 1
sampleProject/app/Http/Middleware/RedirectIfAuthenticated.php Datei anzeigen

@@ -18,7 +18,7 @@ class RedirectIfAuthenticated
18 18
     public function handle($request, Closure $next, $guard = null)
19 19
     {
20 20
         if (Auth::guard($guard)->check()) {
21
-            return redirect('/home');
21
+            return redirect('/backend');
22 22
         }
23 23
 
24 24
         return $next($request);

+ 108
- 0
sampleProject/app/Http/Services/Backend/ZooManagement/TigerManagementService.php Datei anzeigen

@@ -0,0 +1,108 @@
1
+<?php
2
+
3
+namespace App\Http\Services\Backend\ZooManagement;
4
+
5
+use App\Models\ZooManagement\TigerManagement;
6
+
7
+class TigerManagementService
8
+{
9
+    
10
+    // 相關私有 model 調用器宣告
11
+    private $tigerManagementDb;
12
+    
13
+    public function __construct()
14
+    {
15
+        // 建構 model 調用器
16
+        $this->tigerManagementDb = new TigerManagement();
17
+    }
18
+    
19
+    /**
20
+     * 取得老虎資訊的列表
21
+     *   排序、分頁均未實現
22
+     * @return array:     返回老虎列表的陣列
23
+     */
24
+    public function getTigers()
25
+    {
26
+        // 取得參數
27
+        // 調用資料庫(或者其他業務邏輯)
28
+        $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->get()->toArray();
29
+        
30
+        // 整理返回值並返回
31
+        return $tigers;
32
+    }
33
+    
34
+    /**
35
+     * 取得單一老虎資訊
36
+     *
37
+     * @param  integer $id : 老虎的自增量
38
+     *
39
+     * @return array:       返回老虎資訊的陣列
40
+     */
41
+    public function getTigerById($id)
42
+    {
43
+        // 取得參數
44
+        // 調用資料庫(或者其他業務邏輯)
45
+        $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->where('id', $id)->first()->toArray();
46
+        
47
+        // 整理返回值並返回
48
+        return $tigers;
49
+    }
50
+    
51
+    /**
52
+     * 新增老虎
53
+     *
54
+     * @param  string $tigerName : 老虎名字
55
+     *
56
+     * @return bool:               返回新增的操作結果
57
+     */
58
+    public function insertTiger($tigerName)
59
+    {
60
+        // 取得參數
61
+        // 調用資料庫(或者其他業務邏輯)
62
+        $res = $this->tigerManagementDb
63
+            ->insert(['tigerName' => $tigerName]);
64
+        
65
+        // 整理返回值並返回
66
+        return $res;
67
+    }
68
+    
69
+    /**
70
+     * 修改老虎
71
+     *
72
+     * @param  integer $id :        老虎的自增量
73
+     * @param  string  $tigerName : 老虎名字
74
+     *
75
+     * @return bool:                返回修改的操作結果
76
+     */
77
+    public function modifyTiger($id, $tigerName)
78
+    {
79
+        // 取得參數
80
+        // 調用資料庫(或者其他業務邏輯)
81
+        $res = $this->tigerManagementDb
82
+            ->where('id', $id)
83
+            ->update(['tigerName' => $tigerName]);
84
+        
85
+        // 整理返回值並返回
86
+        return $res;
87
+    }
88
+    
89
+    /**
90
+     * 刪除老虎
91
+     *
92
+     * @param  integer $id : 老虎的自增量
93
+     *
94
+     * @return bool:         返回刪除的操作結果
95
+     */
96
+    public function deleteTigerById($id)
97
+    {
98
+        // 取得參數
99
+        // 調用資料庫(或者其他業務邏輯)
100
+        $res = $this->tigerManagementDb
101
+            ->where('id', $id)
102
+            ->delete();
103
+    
104
+        // 整理返回值並返回
105
+        return $res;
106
+    }
107
+    
108
+}

+ 13
- 0
sampleProject/app/Models/ZooManagement/TigerManagement.php Datei anzeigen

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace App\Models\ZooManagement;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class TigerManagement extends Model
8
+{
9
+    protected $connection = 'mysql';                         // 參照 config/database.php 的連線名稱
10
+    protected $table      = 'zooManagement_tigerManagement'; // 表名需符合命名規範
11
+    protected $primaryKey = 'id';                            // PK 的欄位名稱
12
+    public    $timestamps = false;                           // 保持 false
13
+}

+ 55
- 0
sampleProject/resources/views/admin/ZooManagement/TigerManagement.blade.php Datei anzeigen

@@ -0,0 +1,55 @@
1
+@extends('admin.master')
2
+
3
+@section('content')
4
+    <div class="row">
5
+        <div class="col-lg-12">
6
+            <div class="panel panel-dark">
7
+                <div class="panel-heading">
8
+                    <div class="row">
9
+                        <div class="col-md-6">
10
+                            <!-- 標題 -->
11
+                            <div class="panel-title">老虎管理</div>
12
+                        </div>
13
+                        <div class="col-md-6" style="text-align: right">
14
+                            <!-- 新增按鈕端點 -->
15
+                            <a class="btn btn-darkblue btn-xs" href="{{ url('/backend/zooManagement/tigerManagement/create') }}"><strong>Add</strong></a>
16
+                        </div>
17
+                    </div>
18
+                </div>
19
+                <table class="table table-hover" cellspacing="0" width="100%">
20
+                    <thead>
21
+                    <tr>
22
+                        <!-- 欄位名稱 -->
23
+                        <th>自增量</th>
24
+                        <th>老虎名字</th>
25
+                        <th></th>
26
+                    </tr>
27
+                    </thead>
28
+                    <tbody>
29
+                    <!-- 列表渲染 -->
30
+                    @foreach($operdata as $tiger)
31
+                        <tr>
32
+                            <!-- 顯示用欄位 -->
33
+                            <td>{{ $tiger['id'] }}</td>
34
+                            <td>{{ $tiger['tigerName'] }}</td>
35
+                            <!-- 控制用按鈕 -->
36
+                            <td style="text-align: right">
37
+                                <form method="post" action="{{ url('/backend/zooManagement/tigerManagement/'.$tiger['id']) }}">
38
+                                    <!-- 編輯 -->
39
+                                    <a class="btn btn-warning btn-xs" href="{{ url('/backend/zooManagement/tigerManagement/edit/'.$tiger['id']) }}">
40
+                                        <strong>Edit</strong>
41
+                                    </a>
42
+                                {{ csrf_field() }}
43
+                                {{ method_field('DELETE') }}
44
+                                <!-- 刪除 -->
45
+                                    <button type="submit" class="btn btn-danger btn-xs"><strong>Delete</strong></button>
46
+                                </form>
47
+                            </td>
48
+                        </tr>
49
+                    @endforeach
50
+                    </tbody>
51
+                </table>
52
+            </div>
53
+        </div>
54
+    </div>
55
+@endsection

+ 130
- 0
sampleProject/resources/views/admin/ZooManagement/TigerManagementEdit.blade.php Datei anzeigen

@@ -0,0 +1,130 @@
1
+@extends('admin.master')
2
+
3
+@section('content')
4
+    <div class="row">
5
+        <div class="col-lg-12">
6
+            <!-- 指定新增的端點 -->
7
+            <form id="EditForm" class="form-horizontal" method="post" action="{{ url('/backend/zooManagement/tigerManagement/store') }}">
8
+                {{ csrf_field() }}
9
+                <div class="panel panel-primary">
10
+                    <div class="panel-heading">
11
+                        <!-- 更改文案 -->
12
+                        <h4 class="panel-title">{{ ($operdata == "") ? "Create " : "Modify " }}老虎</h4>
13
+                    </div>
14
+                    <div class="panel-body">
15
+                        <div>
16
+                            <!-- 表格本體 -->
17
+                            <table class="table" cellspacing="0" id="DetailsView1" style="border-collapse:collapse;">
18
+                                <tbody>
19
+                                <!-- 欄位:自增量 -->
20
+                                @if ($operdata == "")
21
+                                    <input type="hidden" name="mode" value="insert" />
22
+                                    <!-- Insert Mode -->
23
+                                @else
24
+                                    <!-- Edit Mode -->
25
+                                    <tr>
26
+                                        <td class="col-lg-2">自增量</td>
27
+                                        <td>
28
+                                            <input name="id" type="hidden" value="{{ $operdata['id'] }}" id="id" />
29
+                                            {{ $operdata['id'] }}
30
+                                        </td>
31
+                                    </tr>
32
+                                @endif
33
+                                <!-- 欄位:老虎名字 -->
34
+                                <!-- ALL Mode -->
35
+                                <tr>
36
+                                    <td class="header-require col-lg-2">老虎名字</td>
37
+                                    <td>
38
+                                        <div class="col-lg-3 nopadding">
39
+                                            @if ($operdata == "")
40
+                                                <input name="tigerName" type="text" value="" maxlength="16" id="tigerName" class="form-control">
41
+                                            @else
42
+                                                <input name="tigerName" type="text" value="{{ $operdata['tigerName'] }}" maxlength="16" id="tigerName" class="form-control">
43
+                                            @endif
44
+                                            <label class="error" for="name"></label>
45
+                                        </div>
46
+                                    </td>
47
+                                </tr>
48
+                                <!-- 下控制按鈕 -->
49
+                                <tr>
50
+                                    <td>&nbsp;</td>
51
+                                    <td>
52
+                                        <div style="text-align: right">
53
+                                            @if ($operdata == "")
54
+                                                <!-- Insert Mode -->
55
+                                                <input type="submit" name="btnUpdate_foot" value="Create" id="btnUpdate_foot" class="btn btn-primary btn-xs" onclick="submitForm();">
56
+                                            @else
57
+                                                <!-- Edit Mode -->
58
+                                                <input type="submit" name="btnUpdate_foot" value="Modify" id="btnUpdate_foot" class="btn btn-primary btn-xs" onclick="submitForm();">
59
+                                            @endif
60
+                                            <input type="button" name="btnBackTo2_foot" value="Back" id="btnBackTo2_foot" class="btn btn-default btn-xs">
61
+                                        </div>
62
+                                    </td>
63
+                                </tr>
64
+                                </tbody>
65
+                            </table>
66
+                        </div>
67
+                    </div>
68
+                    <!-- panel-body -->
69
+                </div>
70
+            </form>
71
+        </div>
72
+    </div>
73
+@endsection
74
+
75
+@section('extjs')
76
+    <script>
77
+        $(document).ready(function() {
78
+            $("#btnBackTo2").click(function() {
79
+                // 上方的返回列表按鈕觸發
80
+                location.href='{{ url('backend/zooManagement/tigerManagement') }}';
81
+            });
82
+            $("#btnBackTo2_foot").click(function() {
83
+                // 下方的返回列表按鈕觸發
84
+                location.href='{{ url('backend/zooManagement/tigerManagement') }}';
85
+            });
86
+            // 初始化需要偵錯的表格
87
+            $('#EditForm').validate();
88
+            // 正規表達驗證初始化
89
+            $.validator.addMethod(
90
+                "regex",
91
+                function (value, element, regexp) {
92
+                    var re = new RegExp(regexp);
93
+                    return this.optional(element) || re.test(value);
94
+                }
95
+            );
96
+            // 各欄位
97
+            $('#tigerName').rules("add", {
98
+                required: true,
99
+                minlength: 1,
100
+                maxlength: 16,
101
+                messages: {
102
+                    required: "老虎名字 length must between 1-16",
103
+                    minlength: "老虎名字 length must between 1-16",
104
+                    maxlength: "老虎名字 length must between 1-16"
105
+                }
106
+            });
107
+        });
108
+        //提交與取消按鈕
109
+        function submitForm() {
110
+            if (!!($("#EditForm").valid()) === false) {
111
+                return false;
112
+            } else {
113
+                $(document).ready(function() {
114
+                    $.blockUI({ css: {
115
+                            border: 'none',
116
+                            padding: '15px',
117
+                            backgroundColor: '#000',
118
+                            '-webkit-border-radius': '10px',
119
+                            '-moz-border-radius': '10px',
120
+                            opacity: .5,
121
+                            color: '#fff'
122
+                        }});
123
+                });
124
+            }
125
+        }
126
+        function cancelValidate() {
127
+            $("#EditForm").validate().cancelSubmit = true;
128
+        }
129
+    </script>
130
+@endsection

+ 4
- 4
sampleProject/resources/views/admin/funmenusdetailedit.blade.php Datei anzeigen

@@ -33,9 +33,9 @@
33 33
                             <label class="col-md-2 control-label">Function Link<br />(Route or Controller Name):</label>
34 34
                             <div class="col-md-3">
35 35
                                 @if ($mode == "insert")
36
-                                    <input id="FunLink" name="FunLink" class="form-control" maxlength="20" type="text" />
36
+                                    <input id="FunLink" name="FunLink" class="form-control" maxlength="128" type="text" />
37 37
                                 @else
38
-                                    <input id="FunLink" name="FunLink" class="form-control" maxlength="20" type="text" value="{{ $datas->FunLink }}" />
38
+                                    <input id="FunLink" name="FunLink" class="form-control" maxlength="128" type="text" value="{{ $datas->FunLink }}" />
39 39
                                 @endif
40 40
                                 <label class="error" for="FunLink"></label>
41 41
                             </div>
@@ -44,9 +44,9 @@
44 44
                             <label class="col-md-2 control-label">Function Description:</label>
45 45
                             <div class="col-md-3">
46 46
                                 @if ($mode == "insert")
47
-                                    <input id="FunDesc" name="FunDesc" class="form-control" maxlength="20" type="text" />
47
+                                    <input id="FunDesc" name="FunDesc" class="form-control" maxlength="128" type="text" />
48 48
                                 @else
49
-                                    <input id="FunDesc" name="FunDesc" class="form-control" maxlength="20" type="text" value="{{ $datas->FunDesc }}" />
49
+                                    <input id="FunDesc" name="FunDesc" class="form-control" maxlength="128" type="text" value="{{ $datas->FunDesc }}" />
50 50
                                 @endif
51 51
                                 <label class="error" for="FunLink"></label>
52 52
                             </div>

+ 7
- 0
sampleProject/routes/web.php Datei anzeigen

@@ -43,5 +43,12 @@ Route::group(['middleware' => 'web', 'prefix' => 'backend'], function () {
43 43
         Route::get('/Funmenus/{menuid}/edit/{id}', 'FunmenusDetailController@edit');
44 44
         Route::post('/Funmenus/{menuid}/store', 'FunmenusDetailController@store');
45 45
         Route::delete('/Funmenus/{menuid}/delete/{id}', 'FunmenusDetailController@delete');
46
+        // 範例: 動物園管理 > 老虎管理
47
+        // 注意以下的路由全都不是 restful api 架構,請參照 controller 文件中的註解
48
+        Route::get('/zooManagement/tigerManagement', 'ZooManagement\TigerManagementController@index');
49
+        Route::get('/zooManagement/tigerManagement/create', 'ZooManagement\TigerManagementController@create');
50
+        Route::get('/zooManagement/tigerManagement/edit/{id}', 'ZooManagement\TigerManagementController@edit');
51
+        Route::post('/zooManagement/tigerManagement/store', 'ZooManagement\TigerManagementController@store');
52
+        Route::delete('/zooManagement/tigerManagement/{id}', 'ZooManagement\TigerManagementController@delete');
46 53
     });
47 54
 });