-2

I'm making a website in Laravel, CSS, and HTML.

The current issue is that my code, won't gather information from files inside the folder "_videos" with this "summon" code.

@foreach ($videos as $video)

    {{$page->title}}

@endforeach

Error message

Warning: Invalid argument supplied for foreach()

Folder: Image of folder

Audun Hilden
  • 59
  • 1
  • 10

2 Answers2

1

Looking at the code and the error you receive

@foreach ($videos as $video)

    {{$page->title}}

@endforeach

The error means that the "$videos" variable isn't an array or an object.

if need more info i recommend you this website https://php.net/manual/en/control-structures.foreach.php

P. Dev
  • 117
  • 7
  • You're right! It's supposed to be a folder. @foreach ($(FOLDERNAME) as $(foldercontent-name) So it takes everything in the foldername, and displays them 1 and 1, calling them (foldercontent-name) – Audun Hilden Apr 26 '19 at 01:54
0

It's because the argument is wrong. Change:

@foreach ($videos as $video)

{{$page->title}}

@endforeach

TO

 @foreach ($videos as $video)

    {{$video->title}}

@endforeach
livreson ltc
  • 661
  • 6
  • 19
  • Thank you for helping. It seems like your answer still doesn't fix the issue. – Audun Hilden Apr 26 '19 at 01:41
  • Updated question with a photo of the folder I'd like to extract information from. – Audun Hilden Apr 26 '19 at 01:43
  • Share your control code and blade code please. Are you fetching data from database? – livreson ltc Apr 26 '19 at 01:43
  • Not using any databases. I'm unsure if I misunderstood the "Control Code" part, but is this OK? Control: https://gyazo.com/a7c22f2f756c0fb67decbd19840d8c56 Blade: https://gyazo.com/a7c22f2f756c0fb67decbd19840d8c56 – Audun Hilden Apr 26 '19 at 01:45
  • 1
    These 2 images are same. We need the `code` in your `Controller`, ex: `Route::get('videos', 'VideoController@index')`, we need the `index` function in your `VideoController`. – Cloud Soh Jun Fu Apr 26 '19 at 01:47
  • Blade can't gather information from system as @Ryan Kozak mentioned. Please share your controller, Model Code and Migration table code – livreson ltc Apr 26 '19 at 01:48
  • I don't have a route::get thing, I could share the github link if you want to, and point you to where the code is? Sorry, heres the blade: https://gyazo.com/61304c3ad00b5e80c3839142f18a629b – Audun Hilden Apr 26 '19 at 01:50
  • ``` @foreach ($page->featured as $featured) @endforeach ``` this part works, but not when I don't do $page, also. $page is located in config.js incase anyone were curious. – Audun Hilden Apr 26 '19 at 01:51
  • Where did you defined your `$featured`? How can `$page` located in `config.js`? `$page` is server-side variable, `config.js` is client side code. You're unable to define server-side variable via client-side code. – Cloud Soh Jun Fu Apr 26 '19 at 01:54
  • a friend of me made a boilerplate thing, i'm just following what he made :D I don't know much about laravel, but I know that the part I copied, works on another website I made, and its 100% the same – Audun Hilden Apr 26 '19 at 01:56