0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

laravelでフォルダ内の動画を表示させたいが、動画を読み込めない。

Posted at

laravelで動画投稿機能を実装しようとしています。
public/strage/videosディレクトリに保存した動画をビューで表示させたいのですが、
動画のウィンドウは表示されるものの、動画が読み込まれません。

検証ツールのコンソールを確認したところ、下記エラーが表示されていました。
GET http://localhost:8080/storage/videos/5.mp4 net::ERR_ABORTED 404 (Not Found)

解決法を教えていただきたいです。

profile.blade.php
@foreach ($posts as $post)
    <video width="640" height="360" controls>
      <source src="{{ asset('storage/videos/'.$post->post_id.'.mp4') }}" type="video/mp4">
      Your browser does not support the video tag.
    </video>
@endforeach
HomeController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use App\Models\PostsModel;
/**
     * プロフィール画面表示
     * return view
     */
    public function profile()
    {
        $user = Auth::user();
        $posts_data = new PostsModel();
        $posts = $posts_data->getPosts()->where('user_id', '=', $user->id)->all();//ユーザーIDで絞り込み
        // dd($posts);
        return view('TrickPost.profile', compact('user','posts'));
    }
PostsModel.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class PostsModel extends Model
{
    use HasFactory;

    /**
     * 動画データを取得
     */
    public function getPosts(){
        //データベースの投稿データ取得
        $posts = DB::table('posts')->get();
        return $posts;
    }
}
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?