-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined associatedModel function in CartItem's __get method #125
Comments
Edited your messages markdown for readability. For multi-line code blocks you have to use three ``` like this before the first and after the last line :) |
i got same issue, which '()' you removed as temp solution ? can you mark it up for my reference ? |
if i had to guess i think you are talking about: if (isset($this->associatedModel)) {
return with(new $this->associatedModel())->find($this->id);
} And yes, $fqcn = MyClass::class;
$instance = new $fqcn()
$instance = new (MyClass::class)();
$instance = new ('\\Namespace\\MyClass')(); So the () should be valid there, the automated tests are working too. Can you please check the value of |
I'm newbie for php and laravel. this my sample controller function store
and this in CartItem.php
so where i should put these codes ?
|
No no, this is just an example.
So use https://en.m.wikipedia.org/wiki/Escape_character https://stackoverflow.com/a/25459324 So in your case you could try: Cart::add($item->id, $item->name, 1, $item->price, $item->weight)
->associate('\\App\\Model\\Product'); Or, what i prefer due to better type hinting (but sometimes is not the right choice for example if Product is not available up until execution so you can not reference it):
@rucky96 Check modelFQCN which is associatedModel directly. If it is not null and model does return null it maybe can not find the model via the id so it maybe got (soft-)deleted. |
Hi,
I was trying to get the associated model from the cart item with
$cartItem->model
. However, it returns null.I have seen that in CartItem class there is a call to the associatedModel function within __get method:
I have not seen where this function is defined. I have removed the '()' and now it works for me, is this a bug?
The text was updated successfully, but these errors were encountered: