How to play a video from storage in laravel?

Member

by lily , in category: PHP Frameworks , 3 months ago

How to play a video from storage in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , 3 months ago

@lily 

To play a video from storage in Laravel, you can follow these steps:

  1. Save the video file in the storage directory of your Laravel project. You can save it in the storage/app/public directory by default.
  2. Create a symbolic link from the public directory to the storage directory by running the following Artisan command: php artisan storage:link
  3. To display the video on a webpage, you can use the
1
2
3
4
<video controls>
    <source src="{{ asset('storage/videos/video.mp4') }}" type="video/mp4">
    Your browser does not support the video tag.
</video>


In the above code:

  • The asset() helper function is used to generate the URL to the video file stored in the storage directory.
  • Replace videos/video.mp4 with the actual path to your video file.
  1. Make sure that your web server is configured to serve files from the storage directory. You may need to update the server configuration to allow access to the files inside the storage folder.
  2. Finally, you should be able to play the video by accessing the route that displays the view with the video tag.


By following these steps, you should be able to play a video from storage in Laravel.