0

I am new to laravel. I am trying to create an update before return view but i am getting Property [Video_Views] does not exist on this collection instance.

This is my code

$vidurl="WZzZdBjnjBwbMJh"; $curvid = videos::where('Video_URL', '=', $vidurl)->get(); $viewsarray = array($curvid->Video_Views);

but when i remove $viewsarray = array($curvid->Video_Views); and let my return view work, i can get every information from $curvid into the page. Meaning my code works fine for selecting and display into the return view page. But i want to perform an update before the returnview page but for some reason the Video_Views in $viewsarray = array($curvid->Video_Views); doesnt exist

These are the columns in mysql table called videos enter image description here I can select all these in the return view page but i can't retrieve any info before the returnview page

Any help would be nice!

  • that would give me the same error because, well in "Video_Views" of my database i somewhat store the array in there. For example in my database you will see "hi","lol","you" and using array($curvid->Video_Views) should fill the array with the amount of strings in it – Jurick Pastechi Genaro Dec 03 '17 at 19:51
  • Maybe this will help: https://stackoverflow.com/questions/41366092/laravel-property-title-does-not-exist-on-this-collection-instance – Lawrence Cherone Dec 03 '17 at 19:58
  • did you try dumping $curvid before returning the view? – Riccardo Dec 04 '17 at 01:23

1 Answers1

0

Try $curvid = videos::where('Video_URL', '=', $vidurl)->first();

instead of $curvid = videos::where('Video_URL', '=', $vidurl)->get();

Or use foreach operator.

Example:

$vidurl="WZzZdBjnjBwbMJh";
$curvid = videos::where('Video_URL', '=', $vidurl)->get();
foreach($curvid as $vid){
    $viewsarray = array($vid->Video_Views);
}
Makashov Nurbol
  • 574
  • 3
  • 13