https://stackoverflow.com/questions/42003061/youtube-get-video-title-from-id
<?php
/*________________________________________________
CREATE NEW VIDEO FORM
------------------------------------------------*/
public function create()
{
return view('admin.videos.create');
}
/*________________________________________________
STORE NEW VIDEO INFORMATION
------------------------------------------------*/
public function store(Request $request)
{
// dd($request) ;
$this->validate($request, [
// 'user_id' => 'required',
'youtube_id' => 'required',
// 'youtube_name' => 'required',
]);
$video = Video::create([
'user_id' => Auth::id(),
'youtube_id' => $request->youtube_id,
'youtube_name' => $this->getYouTubeTitle($request->youtube_id)
]);
Session::flash('success', 'Video created succesfully.');
return redirect()->route('video.index');
}
/*________________________________________________
GET YOUTUBE VIDEO TITLE FROM YT API
------------------------------------------------*/
public function getYouTubeTitle($ref) {
$json = file_get_contents('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=' . $ref . '&format=json'); //get JSON video details
$details = json_decode($json, true); //parse the JSON into an array
return $details['title']; //return the video title
}