We need some more data!
- What have you tried?
- What is the data you have?
- You posted before about videos, is this youtube/vimeo/etc. ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am after a little bit of advice on creating a videos page please.
We need some more data!
I've tried a method that involves a new table in my database which consists of id , title, category, YouTube link and the duration so I've just been setting that up as a migration. I am also thinking of adding a new model called Video
But I've currently just been setting up the views how I would like them so I can see how they would look and the videos are hard coded in at the moment.
I've decided to use VideoJs is it possible to store a YouTube or Vimeo URL from a database and pass it to a view which loads the video?
@RobertDBroley of course, I would suggest creating a Video model too as you were saying, however, depending on what you're doing at the moment you will need to:
// Within your controller, using a Video model, you'd do something like this
$video = Video::find(1);
return view('videos.show', compact('video'));
<video id="example_video_1" class="video-js vjs-default-skin"
controls preload="auto" width="640" height="264"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{"example_option":true}'>
<source src="{{$video->url }}" type='video/mp4' />
<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
</video>
I'm just doing my database called video. So far I have an id title, category, slug, and duration. But I have planned my page out so that
A user goes to the library page, they must be logged in. If not redirect to the signup page. If they are signed in then they can choose a video category, once they have chosen a category it takes them to a list of videos associated with that category.
They click a link that takes them to the video page. Would I just require one model and then multiple controllers for each step?
Does this migration for a videos table look okay:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateVideoTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('video', function(Blueprint $table)
{
$table->increments('id');
$table->text('title');
$table->text('category');
$table->string('url_slug');
$table->text('description');
$table->string('video_url');
$table->time('duration');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('video');
}
}
}
@RobertDBroley No. You have three fields named "video_url" I'm sure that is a mistake, but please copy & paste exactly as your migration file is.
You may want a description in there too.
A word of advice, don't forget, it can always be changed. If you're just starting out, never worry about getting it 100% perfect straight away.
@mstnorris don't know what happened there. I've amended my code.
@RobertDBroley looks good to me.
You can always expand on it in the future by adding a tags table.
This line doesn't look good to me...
$table->time('video_url');
Amend that before migrating too. Swap it from time to string
Try to do it by yourself and post when you get stuck. We wont code your website step by step.
I have just got this error when running php artisan migrate.
Robert@ROBERT-PC /C/Code/Laravel
$ php artisan migrate
[PDOException]
SQLSTATE[HY000] [2002] No connection could be made because the target machi
ne actively refused it.
I am able to add a new user to the database. I am using Homestead and MySQL Workbench on Windows 7
Are you SSH'd into Homestead? It doesn't look like it. You need to run everything database related within Homestead.
Oh okay. I usually run from anywhere on my machine homestead up and runs Homestead. As MySQL Workbench is installed on my machine.
Well of course you need to run homestead up from your host machine because, well, Homestead wouldn't be running until you've done that ;)
But once it is up then do your DB stuff inside.
But if I am working locally as I have my Laravel mapped to folder in C:/Code/Laravel I should not have to SSH into Homstead should I? Only started using Homestead a week ago, before that I was using Xammp.
Well I have to on my Mac as it doesn't like the Database connection but maybe things are different on a PC. Maybe see what others have to say.
I just thought it was strange as I have tested the connection and its fine. The ports are correct as the documentation suggest and I was able to signup a new user. Thanks for your help @mstnorris
@RobertDBroley I hope this isn’t for a video on demand site protected behind a paywall. If you’re using YouTube or Vimeo to host the videos, then as soon as some one logs in they can grab the video URL and distribute it to their friends.
The only exception to this is Vimeo, which allows you to restrict playback to specified domains, but you need a PRO account for this, which is $199 annually.
@martinbean No its nothing like that its just some videos from my personal portfolio of work. I may consider Vimeo Pro.
Ive managed to sort the issue following https://scotch.io/tutorials/login-with-the-built-in-laravel-5-scaffolding
I had to login using homestead ssh change my directory to where my local copy is installed C:/Code/Larave then simply run php artisan migrate and it makes the table.
@RobertDBroley what do you mean? If you're referring to running your migrations then that is what I said earlier, no?
I'm not sure I understand what problem you're referring to, are you still having issues connecting to the database?
@mstnorris No sorry my mistake. Thats fine ive sorted that I had SSH into Homestead. I'm just looking at mass populating the database with data to test.
I see, well if you need a hand you know where we are. Good luck.
I am having some trouble with Adding data into my Videos table. I have watched this video https://laracasts.com/series/laravel-5-fundamentals/episodes/8 But I still cant use the database locally as I get the error I had previously. I can use it through SSH but some of the commands Jeffrey uses dont appear for me.
Surely I shoule be able to use MySQL Workbench locally and work on my local project. I know that I need Homstead to run to see my application working. It just seems a bit backwards so to speak.
Why does it seem backwards, Homestead is your server, and MySQL runs on said server so of course it needs to be running. That's like saying, "I have files on my computer but why does it need to be switched on for me to view them?"
As for the settings you need to use to access the DB from MySQL Workbench, take a look at this screenshot:

Obviously just change the Database name and you'll be good to go.
Ive done all that, it works as I have added a new user, tested the connection, that works. But if I have a copy locally on my machine including the database and Homesteads the server and they both are mapped, then I should be able to work locally and just have Homestead running in the background. Its probably a Windows issue. I will start a new question, if that okay. Keep it separate from this.
I want to add data into the newly created table. I can run php artisan tinker I am able to follow the video I mentioned but when I save the data I get that same error which I had today.
[PDOException]
SQLSTATE[HY000] [2002] No connection could be made because the target machi
ne actively refused it.
Now I have checked locally and the migration is there. And MySQL Workbench is running.
Please or to participate in this conversation.