I started learning Laravel since yesterday and face some difficulties to get property of an object.
Here is the class (created with artisan
) :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Task extends Model
{
public $description;
public $completed;
public $timestamps = false;
public function isComplete()
{
return $this->completed;
}
}
And here is the issue :
>>> $tasks = App\Task::all();
=> Illuminate\Database\Eloquent\Collection {#654
all: [
App\Task {#652
id: "1",
description: "Learn Laravel",
completed: "0",
},
],
}
>>> $tasks[0]->id
=> 1
>>> $tasks[0]->description
=> null
Why can I access the id
but not the description
?
via JazZ