1. Go to this page and download the library: Download bekwoh/laravel-media-secure library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bekwoh / laravel-media-secure example snippets
namespace App\Policies;
use App\Models\Document;
use App\Models\User;
class DocumentPolicy
{
public function view(User $user, Document $document): bool
{
return $user->id === $document->user_id;
}
public function stream(User $user, Document $document): bool
{
return $user->id === $document->user_id;
}
public function download(User $user, Document $document): bool
{
return $user->id === $document->user_id;
}
}
// Get the view URL
// https://your-app.com/media/view/some-random-uuid
$view_url = get_view_media_url($media);
// Get the download URL
// https://your-app.com/media/download/some-random-uuid
$download_url = get_download_media_url($media);
// Get the stream URL
// https://your-app.com/media/stream/some-random-uuid
$stream_url = get_stream_media_url($media);