PHP code example of yzh52521 / think-laravel-orm

1. Go to this page and download the library: Download yzh52521/think-laravel-orm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yzh52521 / think-laravel-orm example snippets





if (!function_exists('env')) {
    /**
     * 提高tp框架的助手函数env的权重,保证tp框架的正常运行
     * 获取环境变量值
     * @access public
     * @param string $name    环境变量名(支持二级 .号分割)
     * @param string $default 默认值
     * @return mixed
     */
    function env(string $name = null, $default = null)
    {
        return \think\facade\Env::get($name, $default);
    }
}




if (! function_exists('collect')) {
    /**
     * 提高laravel-orm的collect助手函数的权重,使得laravel orm正常运行
     * Create a collection from the given value.
     *
     * @param  mixed  $value
     * @return \Illuminate\Support\Collection
     */
    function collect($value = null)
    {
        return new \Illuminate\Support\Collection($value);
    }
}

"extra": {
    "erride.php"
    ]
}

composer dump



return [
    // 数据库类型
    'driver' => env('database.type', 'mysql'),

    // 服务器地址
    'host' => env('database.hostname', '127.0.0.1'),

    // 数据库名
    'database' => env('database.database', ''),

    // 用户名
    'username' => env('database.username', 'root'),

    // 密码
    'password' => env('database.password', ''),

    // 数据库编码默认采用utf8mb4
    'charset' => env('database.charset', 'utf8mb4'),

    // 数据库排序的规则默认采用utf8mb4_unicode_ci
    'collation' => env('database.collation', 'utf8mb4_unicode_ci'),

    // 数据库表前缀
    'prefix' => env('database.prefix', ''),
];



use Illuminate\Database\Capsule\Manager as DB;

$users = DB::table('users')->where('id', '>', 1)->get();

php think make:laravel-model User


declare (strict_types = 1);

namespace app\model;

use Illuminate\Database\Eloquent\Model;


class User extends Model
{

   protected $table = 'user';

}


$users = User::all();

dd($users);