-1

I am looking for some package or the correct way that the user can through an input add the url of a youtube video and it is added correctly and previewed.

My code Create:

$properties = Property::create([
    'video' =>  $this->video,
])

View:

<input wire:model="video" class="form-control" type="text" placeholder="Url youtube">

If I add it as a url the video is not shown and it previews the url. it works if i insert it as iframe.

Could you help me how it could be done by directly inserting the address of the video?

maraet
  • 259
  • 7
  • 22

1 Answers1

1

Looking at the YouTube Embedded Players and Player Parameters page, embedded videos' URL should be in this format https://www.youtube.com/embed/VIDEO_ID and be inside an iframe:

<iframe id="ytplayer" type="text/html" width="640" height="360"
  src="https://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
  frameborder="0"></iframe>

So you need to extract the VIDEO_ID from the. I'll borrow some code from another SO answer and suggest this code:

$url = 'https://www.youtube.com/watch?v=C4kxS1ksqtw&feature=relate';
parse_str(parse_url($url, PHP_URL_QUERY), $my_array_of_vars);
echo $my_array_of_vars['v'];

// Output: C4kxS1ksqtw
itainathaniel
  • 655
  • 1
  • 6
  • 12
  • Thanks for your help, once you get the C4kxS1ksqtw output you should insert it into the ID. and at http://example.com the full address? I would have to have two fields in the table one for the ID and one for the full URL? – maraet Nov 16 '20 at 21:20
  • ready works perfect! I did it as you indicated but with the iframe as follows: thanks!! – maraet Nov 16 '20 at 22:33