invalid argument supplied for foreach() - Blade - php

Invalid argument supplied for foreach() (View: /home/securefr/public_html/resources/views/themes/gameshop/buy.blade.php)
<div class="row g-2 mt-3 more-info">
#forelse($item->post_specification_form as $k => $v)
<div class="col-6">
<span>{{$v->field_name}}: {{$v->field_value}}</span>
</div>
#empty
#endforelse
</div>
https://flareapp.io/share/omwQrlZ7#F62L142
Ive tried a few different answers on here, but just cant get it to shift!

First of all, you should not share an exception from live app that is hosted somewhere on the web, there is too much data that can be used to do something malicious.
But using tab "App" from Flare bug, it seems that you didn't passed an argument in view or your object has missing property, so null is not valid argument for your foreach - that's what error message says.

Related

Undefined variable: updates - in Homepage Sponzy template

I have tried to call the function "#include('includes.updates')" and it throws me the error "ErrorException
Undefined variable: updates"
In hompage there are other functions like " #include('includes.listing-creators')" that when called work normally but I don't know why "include.updates" doesn't work.
#if ($updates->total() != 0)
<div class="grid-updates position-relative" id="updatesPaginator">
#include('includes.updates')
</div>
#endif
The code "#include('includes.updates')" should call the list of posts published by users, it is not working on homepage as I mentioned before. Could someone help me how to call the function to make it work on homepage?
I share link of the code that I am using and I want to modify:
https://codecanyon.net/item/sponzy-support-creators-content-script/28416726

Laravel 8 Jetstream || Undefined variable: _instance (View: C:\xampp\htdocs\veye-website\resources\views\vendor\jetstream\components\modal.blade.php

I am trying to use Laravel 8 Livewire Modal Popup for data entry with going on another page. But I get undefine the variable _instance and not able to understand it.
#entangle($attributes->wire('model'))
This line creates this error when I remove this from views/vendor/jetstream/components/modal.blade.php. the error will go.
Line no 34.
<div id="<?php echo e($id); ?>" x-data="{ show: <?php if ((object) ($attributes->wire('model')) instanceof \Livewire\WireDirective) : ?>window.Livewire.find('<?php echo e($_instance->id); ?>').entangle('<?php echo e($attributes->wire('model')->value(
x-show="show"
x-on:close.stop="show = false"
x-on:keydown.escape.window="show = false"
class="fixed top-0 inset-x-0 px-4 pt-6 sm:px-0 sm:flex sm:items-top sm:justify-center"
style="display: none;">
This was causing me much angst too but I think I found the solution: as #georgy-malanichev says, you can only call Livewire methods from inside a Livewire component (and not from inside a Blade component or any other custom components).
Given you are trying to use the component inside resources/views/dashboard.blade.php, the solution is to:
create a livewire component using artisan make:livewire MyDashboard
Cut everything between <x-app-layout> and </x-app-layout> in dashboard.blade.php and paste it into views/livewire/my-dashboard.blade.php
Add #livewire('my-dashboard') inside the x-app-layout tags and Bob's your uncle (it should start working)
To help you understand what's going on, if you look at the source code for the modal component, you'll see a line like: show: #entangle($attributes->wire('model')),. I'm not sure how to describe exactly what this does, but, essentially, #entangle() is expecting an instance of the "model" Livewire object and it's not finding one.
It's not finding it because it's getting called from a non-livewire component. Once you put it inside a Livewire component, it starts working.
I hope the additional details makes things clearer.
I was getting the same error but in my case it was the fact that I had x-data="{ open: #entangle('showDropdown') }" outside of the LiveWire component. Once I moved it inside the component template, where it should be, the issue went away.

Laravel DD prints right variable but 'non-object'

I've encountered a strange error when using laravel. So essentially when I call this
{{ $product->images()->first()->fileName }}
I get the following error
Trying to get property 'fileName' of non-object
However, when I call it in dd it shows the variable fine...
#dd($product->images()->first()->fileName);
So I'm not really sure whats wrong, 'images' is related by a hasMany call in product. Would love some advice on whats going on here!
This is a simple, but not necessarily ideal solution:
#php $image = $product->images()->first(); #endphp
#if($image)
<img src="{{ $image->fileName }}"/>
#endif
Since, you are iterating over the products, one of the products must not have an image.
Without changing your code much, just add an # before the statement
{{ #$product->images()->first()->fileName }}
This will automatically handle the error and return null. So, your program won't crash.
See PHP Error Control Operators

Laravel "{slug}" not being replaced, instead being url encoded

I've recently embarked on learning Laravel. In doing so I've began completing tutorials from around the web, including from youtube. In one such tutorial I've been developing a very basic blog. I've hit something of an impasse when working with slugs. For some reason, it just doesn't want to work for me!
When the following code is entered in my 'routes.php' file, I have noticed that the braces '{' and '}' are automatically converted to URL encoding and the word "slug" is displayed. Additionally, the '/' following the word posts is nowhere to be seen. This means a link will read as "http:[domain name]/posts/%7Bslug%7D[article name]"
Route::get('/posts/{slug}', [
'as' => 'post-show',
'uses' => 'PostController#getIndex'
]);
The problem is partially resolved if I change the code thus:
Route::get('/posts/{slug?}', [
'as' => 'post-show',
'uses' => 'PostController#getIndex'
]);
The word "slug" is no longer displayed as part of the URL. However, for some reason the slug's preceding '/' is still not visible, as though eaten by the slug in question! It now reads "http:[domain name]/posts**%7Bslug%7D**[article name]".
I'd really appreciate pointing in the right direction if anyone can lend a hand. Thank you.
Based on your comment, the way you're calling the action is incorrect. Try this view code:
#if ($posts->count())
#foreach ($posts as $post)
<article>
<h2>{{ $post->title }}</h2>
{{ Markdown::parse(Str::limit($post->body, 157)) }}
read more…
</article>
#endforeach
#endif
I am not near a terminal to test this, but it should get you closer. The problems this code addresses are:
To generate a URL using the route name, use route. Your code was using action.
To pass a parameter and fill in the "{slug}", you pass an array as the second argument to route (and action for that matter). Your code was neither passing an array nor passing the value into the function.
You were missing a } after the Markdown::parse, but that may have been a copy & paste error.
If this helped you, remember to up vote and mark as accepted!

Undefined variable in custom Drupal module

I write custom Drupal module. Want show field_myear in contents. With the following:
<div class="right">
<h4>'.$m_detail->title.'</h4>
<div class="section">'.$field_myear.'</div>
<div class="description">
<div
But when refresh page, get this error:
Notice: theme_news()/home/domains/site.net/public_html/sites/all/modules/site/theme.module dosyasının 1247 satırı) içinde Undefined variable: field_myear.
How can i fix it?
Follow the execution of your page. Step through it line by line. When you are outputting the HTML shown above, you haven't got a value set for field_myear. You need to be sure you are setting it prior to trying to output it - or you need to check your variable name to make certain that it is correct and doesn't have a typo in it.

Categories