PHP code example of nestednet / laravel-attachments
1. Go to this page and download the library: Download nestednet/laravel-attachments library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$user = App\User::first();
$attachmentByKey = $user->attachment('myKey');
$attachmentByKey->delete(); // Will also delete the file on the storage by default
useBnb\Laravel\Attachments\Attachment;
classAppServiceProviderextendsServiceProvider{
// ...publicfunctionboot(){
// ...
Attachment::outputting(function($attachment){
/** @var Attachment $attachment */// Get the related model
$model = $attachment->model;
if (empty($model)) {
// Deny output for attachments not linked to a modelreturnfalse;
}
if ($model instanceof \App\User) {
// Check if current user is granted and owner
$user = \Auth::user();
return $user && $user->can('download-file') && $user->id == $model->id;
}
});
// ...
}
// ...
}