我不确定这里发生了什么.我更改了数据库名称.我已经进入phpMyAdmin并复制并粘贴名称,以确保数据库是正确的.这是我的代码.
class DB {
private static $_instance = null;
private $_pdo,
$_query,
$_error = false,
$_results,
$_count = 0;
private function __construct() {
try{
$this->_pdo = new PDO('mysql:host='. Config::get('mysql/host') . ';dbname= ' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
} catch(PDOException $e){
die($e->getMessage());
}
}
public static function getInstance(){
if(!isset(self::$_instance)){
self::$_instance = new DB();
}
return self::$_instance;
}
}
Run Code Online (Sandbox Code Playgroud)
这是config的类,
class Config {
public static function get($path = null){
if($path){
$config = $GLOBALS['config'];
$path = explode('/', $path);
foreach($path as $bit){
if(isset($config[$bit])){
$config = …Run Code Online (Sandbox Code Playgroud) 我不确定这真的是一个 Laravel 问题,但是,当我 dd(die and dump) 这个 dd($user->friends()); 我得到以下信息。我确实注意到这是一个集合。我不确定这是否意味着不同的东西。但它仍然应该是我相信的一系列项目。第一个用户在 [0] 标记和下一个 [1] 等...
Collection {#184 ?
#items: array:2 [?
0 => User {#189 ?
#table: "users"
#fillable: array:7 [?]
#hidden: array:3 [?]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:11 [?]
#original: array:13 [?]
#relations: array:1 [?]
#visible: []
#appends: []
#guarded: array:1 [?]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
1 => User …Run Code Online (Sandbox Code Playgroud)