Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RobertDBroley's avatar

Videos Page

I am after a little bit of advice on creating a videos page please.

0 likes
33 replies
bobbybouwmann's avatar

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. ?
RobertDBroley's avatar

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.

RobertDBroley's avatar

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?

mstnorris's avatar

@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:

  1. Get the URL, from your model and pass it to your view using a VideosController (or whatever you're using)
// Within your controller, using a Video model, you'd do something like this
$video = Video::find(1);

return view('videos.show', compact('video'));
  1. Use it in your view (videos/show.blade.php)
<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>
RobertDBroley's avatar

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?

RobertDBroley's avatar

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');
    }
    }

}

mstnorris's avatar

@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.

joedawson's avatar

This line doesn't look good to me...

$table->time('video_url');

Amend that before migrating too. Swap it from time to string

pmall's avatar

Try to do it by yourself and post when you get stuck. We wont code your website step by step.

RobertDBroley's avatar

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

mstnorris's avatar

Are you SSH'd into Homestead? It doesn't look like it. You need to run everything database related within Homestead.

RobertDBroley's avatar

Oh okay. I usually run from anywhere on my machine homestead up and runs Homestead. As MySQL Workbench is installed on my machine.

mstnorris's avatar

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.

RobertDBroley's avatar

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.

mstnorris's avatar

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.

1 like
RobertDBroley's avatar

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

martinbean's avatar

@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.

RobertDBroley's avatar

@martinbean No its nothing like that its just some videos from my personal portfolio of work. I may consider Vimeo Pro.

mstnorris's avatar

I'm not sure I understand what problem you're referring to, are you still having issues connecting to the database?

RobertDBroley's avatar

@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.

mstnorris's avatar

I see, well if you need a hand you know where we are. Good luck.

1 like
RobertDBroley's avatar

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.

mstnorris's avatar

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.

RobertDBroley's avatar

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.

http://postimg.org/image/w1e8c12hj/

1 like
mstnorris's avatar

@RobertDBroley

  1. What is it exactly you are trying to achieve?
  2. What do you thin is supposed to happen? (Just so we're on the same page)
RobertDBroley's avatar

@mstnorris

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.

Next

Please or to participate in this conversation.