0

have This code

Session.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 (cropped)

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 [▶]
    }
  ]
}

What I'm doing wrong?

I want to see Data from Database not current data! Maybe I have mistake with Model or maybe I don't understand how I can do this with Laravel helpers

Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

0

Delete Session and instead use the class which the framework provides (based on the dd, you're probably not even using it). Not sure if it still works with Laravel 8, but Session::instance()->session['data'] appears more likely. If everything fails, you still could use DB and query table sessions.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • `Session::instance()->session['data']` Result `ArgumentCountError Too few arguments to function Illuminate\Session\Store::get(), 0 passed in /Users/pavel/Desktop/Development/1xbetBasicIgor/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 156 and at least 1 expected` – Павел Игоревич Jan 16 '21 at 19:31
  • 1
    ```$sessionData = DB::table('sessions')->select('ip_address')->groupBy('ip_address')->distinct()->get(); $uniqueViewvers = $sessionData; $uniqueViewvers->count(); ``` Why Count() don't working? – Павел Игоревич Jan 16 '21 at 19:51