First apologies for the title, I couldn't think of a better description. I have a controller that is suppose to read a database then return it as an object. This database recently went through a change in structure, and I re-seeded it. My controller code is:
$books = \App\book::where('userId',1)->get();
foreach ($books as $b) {
echo$b->bookId;
}
This will result in the following out output:
70008000
.
However, if I run the same through tinker I get an entirely different result. Tinker code: App\Book::where('userId',1)->get();
will result in several records such as:
Illuminate\Database\Eloquent\Collection {#3018 all: [ App\book {#2996 recordId: 1, bookId: "7iraCwAAQBAJ", userId: 1, authorId: 1, title: "The Witch of Lime Street", isbn: "9780307451064", description: "In 1924 the wife of a Boston surgeon came to embody the raging national debate over Spiritualism, a movement devoted to communication with the dead. Reporters dubbed her the blonde Witch of Lime Street, but she was known to her followers simply as Margery. Her most vocal advocate was Sir Arthur Conan Doyle, who believed so thoroughly in Margery's powers that he urged her to enter a controversial contest, sponsored by Scientific American. Her supernatural gifts beguiled four of the judges. There was only one left to convince ... the acclaimed escape artist, Harry Houdini. Jaher captures their electric public rivalry and the competition that brought them into each other's orbit.", preview: "http://books.google.com/books?id=7iraCwAAQBAJ&dq=9780307451071&hl=&source=gbs_api", cover: "http://books.google.com/books/content?id=7iraCwAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api", book_status: "reading", created_at: "2019-08-16 12:30:27", updated_at: "2019-08-16 12:30:27", },
In the result you will see that I highlighted the bookId. That is what I expect to return when I run it through my controller.
EDIT
Database
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->bigIncrements('recordId');
$table->string('bookId');
$table->integer('userId');
$table->integer('authorId');
//$table->integer('genreId');
$table->string('title');
$table->string('isbn');
$table->binary('description');
$table->string('preview');
$table->string('cover');
$table->string('book_status');
$table->timestamps();
});
//DB::statement('ALTER TABLE books AUTO_INCREMENT = 2000');
}
Eloquent Model
class book extends Model
{
protected $primaryKey = 'bookId';
protected $fillable = [
'bookId',
'userId',
'authorId',
'title',
'isbn',
'description',
'preview',
'cover',
'book_status'
];
//$guarded = [];
public function authors(){
return $this->belongsTo('App\author','authorId');
}
}