因此,首先我開始使用laravel和php的整體工作。現在我遇到了一個問題,我不知道如何從我的數據庫中顯示特定的視頻。我的用戶模型:Laravel如何通過它的ID顯示視頻
class User extends Model implements Authenticatable{
use \Illuminate\Auth\Authenticatable;
public function videos() {
return $this->hasMany('App\Video');
}
}
我的視頻模式:
class Video extends Model{
public function user() {
return $this->belongsTo('App\User');
}
}
一切順利的話,當我依次通過我的影片在儀表板顯示它們:
<div class="row" id="features">
@foreach($videos as $video)
<div class="col-sm-4 feature">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title video_name">{{ $video->video_name }}</h3>
</div>
<iframe width="320" height="250"
src="https://www.youtube.com/embed/{{ $video->video_url }}" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen">
</iframe>
<div class="info">
<p>Posted by {{ $video->user->first_name }} on {{ $video->created_at }}</p>
<hr class="postInfo">
</div>
<p>{{ $video->description }} </p>
<a href="{{ route('view.video', [$video->id]) }}" class="btn btn-danger btn-block">Continue to video</a>
</div>
</div>
@endforeach
</div>
但在這一點:
<a href="{{ route('view.video', [$video->id]) }}" class="btn btn-danger btn-block">Continue to video</a>
I ope N個新的路線是(http://localhost:8000/video/11/view),在這種情況下,我想其中ID 11等於我VIDEO_URL
視頻表的代碼顯示視頻:
public function up(){
Schema::create('videos', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->text('video_name');
$table->text('video_url');
$table->text('description');
$table->integer('user_id');
});
}
路線:
Route::get('/video/{video_id}/view', [
'uses' => '[email protected]',
'as' => 'view.video']);
它的工作<3這樣一個簡單的解決方案,謝謝了很多! :) – Arthur