Closed psychonetic closed 6 years ago
OMG! I created a new project and as always it was working fine, but it never did with yours, it drove me crazy and consumed few hours until I figured you're using custom primary key for your model which I didn't notice before, and that made sense then!! Thank god it's now solved with one tiny simple change 17b043145a518460d8cd4acf64320ba86d8ac251
composer update
and you'll be good to go. Thanks @psychonetic for your persistence 😅 This was a tricky one. Happy to help if you need further assistance 😉
@Omranic Sorry, but I need to bother you again and the issue is still not fixed. The method getKey returns the value of the primary key and not the name of the primaryKey.
/**
* Get the value of the model's primary key.
*
* @return mixed
*/
public function getKey()
{
return $this->getAttribute($this->getKeyName());
}
You should change getKey
to getKeyName. That should to the trick. Otherwise an exception is thrown, because some of your methods require a string, but if you use getKey() it returns certainly an int.
@Omranic
I added a pull request.
My bad! 😅 PR merged 👌
Soo @Omranic.
I followed your steps and created a new laravel project and I am still unable to get the data. Here is the link to the repo: https://github.com/psychonetic/laravel-attributes
Just migrate the database, run php artisan serve and hit the following url: localhost:8000/api/articles.
A size attribute is created, after an article and also applied the size to the article and finally I try to get the result. But as already discussed in #26 the size is always null.
Best regards,
Marco