I have a user with some calls in my project and every call belongs to one user. I have used laravel elequent relationships to retrive a user calls as following: user model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = 'customers';
public function customer_logs()
{
return $this->hasMany('App\call_log');
}
call model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class call_log extends Model
{
protected $table = 'customer_logs';
public function customer()
{
return $this->belongsTo('App\User');
}
but when I call customer_logs function in my controller I face this error: Undefined property: Illuminate\Database\Eloquent\Collection::$customer_logs
this my controller:
$user = User::first()->get();
$user->customer_logs->toArray();