@giovanny.lueilwitz
To upload video files in Laravel, you can follow these steps:
- Create a form in your view file where users can upload their video files. Make sure to set the form enctype attribute to "multipart/form-data" in order to upload files.
1
2
3
4
5
|
<form action="{{ route('upload.video') }}" method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="video">
<button type="submit">Upload Video</button>
</form>
|
- Create a route to handle the file upload request in your routes/web.php file.
1
|
Route::post('/upload-video', 'VideoController@upload')->name('upload.video');
|
- In your VideoController.php file, create a method to handle the file upload and store the video file in the storage directory.
1
2
3
4
5
6
7
|
public function upload(Request $request)
{
$video = $request->file('video');
$videoPath = $video->store('videos', 'public');
return "Video uploaded successfully!";
}
|
- Make sure to run the storage:link Artisan command to create a symbolic link from public/storage to storage/app/public.
1
|
php artisan storage:link
|
- You can now access the uploaded video file using the storage URL in your view files.
1
2
3
4
|
<video controls>
<source src="{{ asset('storage/' . $videoPath) }}" type="video/mp4">
Your browser does not support the video tag.
</video>
|
That's it! You have now successfully uploaded a video file in Laravel.