How to show a video path in laravel?

by elise_daugherty , in category: PHP Frameworks , 5 months ago

How to show a video path in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 5 months ago

@elise_daugherty 

To show a video path in Laravel, you can use the public_path() function to get the full path to the public directory of your Laravel application. Then, you can append the relative path of the video file to the public path.


Here is an example of how you can show a video path in Laravel:

1
$videoPath = public_path('videos/sample-video.mp4');


In this example, public_path('videos/sample-video.mp4') will return the full path to the sample-video.mp4 file located in the videos directory within the public directory of your Laravel application.


You can then use this $videoPath variable in your Blade template or controller to display or serve the video file. For example, in a Blade template, you can use the asset() helper function to generate a URL for the video file:

1
2
3
4
<video controls>
    <source src="{{ asset('videos/sample-video.mp4') }}" type="video/mp4">
    Your browser does not support the video tag.
</video>


This will create a video element with the sample-video.mp4 file as the video source. The asset() helper function will generate the correct URL to the file based on the current application URL.