mercredi 17 novembre 2021

Laravel ::all() command only returns 1 record

Hi guys I am trying to get all the records from a table in my database using $pools = \App\pool::all();
The database currently has 3 records in it but only the first record is returned

foreach($pools as $pool)
    {return $pool;}

{"poolId":1,"poolName":"TestPool","pAdminId":70,"poolStatus":1,"created_at":"2021-11-17 08:06:57","updated_at":"2021-11-17 08:06:57"}

My SQLDB

This has not been a problem before when using ::all() The same is true when using

$pools = \App\Pool::where('pAdminId',$user->id)->get();

The $user->id returns 70, this is also happening for another table of mine Poolmembers, both were created using the php artisan make:model command and rolled back once to change a datatype and then migrated again.

The model for pool looks as follow


namespace App;

use Illuminate\Database\Eloquent\Model;

class Pool extends Model
{
    //
    protected $primaryKey = 'poolId';
    protected $fillable = ['poolId', 'poolName', 'pAdminId', 'poolStatus'];
}

Any help would be appreciated

Thank you




Aucun commentaire:

Enregistrer un commentaire