我正在尝试将视频嵌入视图中,但是我收到的是404,但我不确定为什么。我创建了一个新的laravel项目,然后进行了php artisan storage:link。这个网站不需要使用文件上传功能,因此我只是将文件粘贴在存储目录中:
storage/app/public/product1/courses/announcements/Manager_Creating_an_Announcement.mp4
我的迁移文件:
public function up()
{
Schema::create('courses', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('title')->nullable($value = true);
$table->string('certifcation')->nullable($value = true);
$table->string('video')->nullable($value = true);
});
}
视频在哪里
我的CourseCountroller
<?php
namespace App\Http\Controllers;
use App\Course;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class CourseController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($id)
{
$course = Course::findOrFail($id);
//dd(Storage::allFiles('public'));
//this returns an array with: 0 => "public/product1/courses/announcement/Manager_Creating_an_Announcement.mp4"
return view('course.index', compact('course', $course));
}
用户单击以转到本课程的视图如下:
<a href="/product/course/1">Manager Creating an Announcement</a>
web.php中的路由如下:
Route::get('/product/course/{course}', 'CourseController@index');
课程视图如下:
@extends('layouts.app')
@section('content')
@php
@endphp
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">Welcome to your course: {{$course->title}}</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<h3>Watch the video first!</h3>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="{{asset($course->video)}}"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
在修补匠中,课程如下:
>>> Course::all();
[!] Aliasing 'Course' to 'App\Course' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#2921
all: [
App\Course {#2922
id: 1,
created_at: null,
updated_at: null,
title: "Manager creating an Announcement",
certifcation: "Announcements",
video: "public/csm/courses/announcement/Manager_Creating_an_Announcement.mp4",
},
],
}
该错误是404错误,找不到页面。当我检查元素时,我看到:
<iframe src="http://127.0.0.1:8000/public/product1/courses/announcement/Manager_Creating_an_Announcement.mp4" class="embed-responsive-item"></iframe>
我还尝试了使用video标签,而不是将其嵌入,但没有成功。任何帮助将不胜感激!
答案 0 :(得分:1)
如果它在存储中,则您运行了sub("^0+(?=[A-Z])", "", c("00MOC0012B", "000001"), perl = TRUE)
# [1] "MOC0012B" "000001"
,您应该可以像这样访问它:
php artisan storage:link
答案 1 :(得分:0)
公用磁盘用于将要公开访问的文件。默认情况下,公用磁盘使用本地驱动程序,并将这些文件存储在storage / app / public中。为了使它们可以从Web上访问,您应该创建一个从public / storage到storage / app / public的符号链接。此约定会将您的公共可访问文件保留在一个目录中,当使用零停机时间部署系统(例如Envoyer)时,可以在各个部署之间轻松共享这些文件。
要创建符号链接,可以使用storage:link Artisan命令:
php artisan storage:link
当然,一旦存储了文件并创建了符号链接,就可以使用资产助手创建指向这些文件的URL:
echo asset('storage/file.txt');