Bladeren bron

tested model

mx 3 jaren geleden
bovenliggende
commit
9dd70c1b28
3 gewijzigde bestanden met toevoegingen van 87 en 1 verwijderingen
  1. 22 0
      app/controller/User.php
  2. 31 0
      app/model/User.php
  3. 34 1
      config/database.php

+ 22 - 0
app/controller/User.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace app\controller;
+
+use support\Request;
+use app\model\User as UserModel;
+
+class User
+{
+    public function index(Request $request)
+    {
+
+        $user = UserModel::first();
+
+        if ($user) {
+            $user->username = 'updated';
+            $user->save();
+        }
+        return json($user);
+    }
+
+}

+ 31 - 0
app/model/User.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace app\model;
+
+use support\Model;
+
+class User extends Model
+{
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected $table = null;
+
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected $primaryKey = 'id';
+
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public $timestamps = false;
+    
+    
+}

+ 34 - 1
config/database.php

@@ -12,4 +12,37 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-return [];
+return [
+    'default' => 'pgsql',
+
+    // all
+    'connections' => [
+        'pgsql' => [
+            'driver' => 'pgsql',
+            'host' => '127.0.0.1',
+            'port' => 5432,
+            'database'=> 'pgt1',
+            'username'=> 'pgt1',
+            'password'=> 'pgt1',
+            'charset'=>'utf8',
+            'prefix'=>'',
+            'schema'=>'public',
+            'sslmode'=>'prefer',
+        ],
+
+        'mysql' => [
+            'driver' => 'mysql',
+            'host'  => '127.0.0.1',
+            'port' => 3306,
+            'database' => 'test',
+            'username' => 'root',
+            'password' => '',
+            'unix_socket' => '',
+            'charset' => 'utf8',
+            'collation' => 'utf8_unicode_ci',
+            'prefix' => '',
+            'strict' => true,
+            'engine' => null,
+        ],
+    ],
+];