有这个代码
会话.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Session extends Model
{
public function scopeAllSessions($query)
{
return $query->get();
}
}
HomeController@index(裁剪)
use App\Models\Session;
$uniqueViewvers = Session::all() ;
return view('pages.admin.index', ['links' => $links, 'metricks' => $metricks, 'uniqueViewvers'=>$uniqueViewvers]);
dd($uniqueViewvers);
Illuminate\Database\Eloquent\Collection {#1266 ▼
#items: array:1 [▼
0 => App\Models\Session {#1267 ▼
#connection: "mysql"
#table: "sessions"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:6 [▶]
#original: array:6 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
]
}
我做错了什么?
我想查看数据库中的数据而不是当前数据!也许我对模型有误,或者我不明白如何使用 Laravel 助手来做到这一点