bnbwebexpertise / laravel-attachments Goto Github PK
View Code? Open in Web Editor NEWLaravel 5.4+ file attachment helpers
Laravel 5.4+ file attachment helpers
Hi, i´m trying to generate one download button to a uploaded file. The upload its ok, i see him in the attachments table, but if i try to get all the attachments from my model, its returns nothing.
I tried this:
$curriculo = Curriculo::find($id);
$file = $curriculo->attachments()->get();
dd($anexos);
And it gives me a empty collection.
And yes, i can see my $id and getting my "curriculo" model fine.
Any idea how i can fix that?
Hi,
I'm trying to add a custom additional field(s) into attachments table,
so first I create a migration to add those fields,
then in the dropzone form I add those input elements
then in my controller:
(I try to attach the UploadedFile directly to the model instead of uploading to dropzone controller first then bind uuid)
$attachment = $user->attach(
$request->file($request->input('file_key', 'file')), // <== the UploadedFile instance
array_merge(array_only($request->input(), [
'title',
'description',
'category', // <== here is the additional field
'key',
]), [
'metadata' => ['dz_session_key' => csrf_token()], // <== actually this also got ignored
]) . // <== the $options argument
);
but this got ignored because
https://github.com/bnbwebexpertise/laravel-attachments/blob/master/src/Attachment.php#L77
so I'm wondering is it necessary to filter out fields other than ['title', 'description', 'key', 'disk'] ?
or was I doing something wrong?
what is the easiest way to achieve what I'm trying to do?
Thanks!!
Hi,
I get this error message when I tried to attach an image to a user,
Here my code :
$avatar = $admin->attach(public_path().'/BKF/DzErpTheme/img/default-avatar.png',[
'disk' => 'media',
'title' => 'avatar',
'description' => 'default avatar',
'key' => 'avatar'.$admin->id,
]);
and here the error :
FatalThrowableError in Uuid.php line 66: Call to undefined function Bnb\Uuid\bcadd()
Please check it.
Hello. Just connected lib to my project with vue-dropzone on frontend.
I worry about too many random folders created with every uploaded file. As i read linux filesystem (ext4fs for example) become slow with too many folders (about 10000 and more). If project is quite large i think there will be even more folder amount. And i can't change this behavior (from documentation). What do you think about it?
I found some link for ext4:
https://ext4.wiki.kernel.org/index.php/Ext4_Howto#Sub_directory_scalability
Hi @gabsource thanks for great package!
Just want to ask a question, will laravel-attachments
support attachment group
?
In my case, a user have a avatar, this can easily done with:
// attach
$user->attach(somefile, ['
'key' => 'avatar',
']);
// get
$user->attachment('avatar');
But how about if user have a personal photo album? I try with:
// with multiple uploads
$user->attach(somefile, ['
'key' => 'album',
']);
But when I want to get all photos with $user->attachment('gallery');
, this only return 1 (last added) photo.
Maybe something like:
// with multiple uploads
$user->attach(somefile, ['
'group' => 'album',
']);
// get Collection
$user->groupAttachments('album');
it would really help me out.
I can add additional column as #8 , but with group
option and the method groupAttachments()
will make it easier to use.
Thanks!
It would be useful to have an example of how this is intended to be used in a view/blade. Especially for images.
Hello,
When I'm trying to run composer require bnbwebexpertise/laravel-attachments
to install the package, I'm getting the following error:
Using version ^1.0 for bnbwebexpertise/laravel-attachments
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Deprecation Notice: Class ParsedownExtraTest located in D:/code/vendor/erusev/parsedown-extra\test\ParsedownExtraTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Illuminate\Contracts\Container\BindingResolutionException
Target [Bnb\Laravel\Attachments\Contracts\AttachmentContract] is not instantiable while building [Bnb\Laravel\Attachments\Console\Commands\CleanupAttachments].
at D:\code\vendor\laravel\framework\src\Illuminate\Container\Container.php:1038
1034▕ } else {
1035▕ $message = "Target [$concrete] is not instantiable.";
1036▕ }
1037▕
➜ 1038▕ throw new BindingResolutionException($message);
1039▕ }
1040▕
1041▕ /**
1042▕ * Throw an exception for an unresolvable primitive.
1 D:\code\vendor\laravel\framework\src\Illuminate\Container\Container.php:839
Illuminate\Container\Container::notInstantiable("Bnb\Laravel\Attachments\Contracts\AttachmentContract")
2 D:\code\vendor\laravel\framework\src\Illuminate\Container\Container.php:279
Illuminate\Container\Container::build("Bnb\Laravel\Attachments\Contracts\AttachmentContract")
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
Do you have any plans to support version 5.6?
Hi team!. I'm using Laravel 5.4, i installed laravel-attachments Version 0.0.16 as suggested in documentation.
I'm storing a file usign Laravel Storage::put()
method, then getting the url with Storage::url(
) and then passing this path to the $model->attach($path, $options)
method.
Basically my problem is that once i execute $model->attach($path, $options)
, a new file is created in the "attachments" folder.
For this project i'm using Amazon s3 Storage and we're not about upgrading Laravel so far.
I really hope you could tell me how could i fix this or tell me what i am doing wrong.
Thanks!
Hello,
I'm using Tenancy and I have a problem with your migrations.
When I do a "artisan migrate:fresh", I don't want your migrations to automatically be run (because I want them for each Tenant, not for the "central app").
Can you do something so we can :
Laravel Sanctum does it very well : https://laravel.com/docs/9.x/sanctum#migration-customization
Thanks !
See attached unit test and conf file.
Set filesystems.default = local
Set 'attachments.behavior.cascade_delete = true
Create an object
Add attachments as in attached unit test
Confirm they are saved to AWS s3
Delete attachments
Delete object
Confirm records are deleted from DATABASE.attachments
Confirm they are STILL saved to AWS s3
If I repeat the steps above but change filesystems.default = s3, files are deleted in BOTH DATABASE.attachments and aws.s3 (expected behavior)
OpportunityRepositoryTest.php.txt
attachments.php.txt
filesystems.php.txt
Hi,
Thanks for the good package
For some reason there is no created folder when I upload images successfully, the uploaded files are saved on the attachment model but I cannot access the given filepath.
Thanks!
When doing a left join I am no longer able to view any of the existing attachments.
Hello, thank you such convenient library! I faced an issue where my model (User) to which I attach my file, locates outside. And therefore User->attachments() doesnt work, because in remote database table attachments doesnt exist. Is there any workaround? Thanks!
I see there is a hidden field that we can update and attach the file in the controller on save, which is beautiful logic. just want to find out what the best approach for multiple uploads with dropzone would be
Hi,
Thanks for this good package,
How can i install it via composer command line ?
hello, i have a model with UUID as a Primary key not ( big int ), so when i try to attach him a file i got an error , incompatible type uuid with big int on column modelèid , how to deal with this ? thanks
I've got extended model FileAttachment to add some relations. But when i use HasAttachment trait, i've got collection of Attachment models instead of FileAttachment.
In AppServiceProvider all bindings correct.
May be it would be nice to have model class name in config/attachments.php that we could have own model class in HasAttachment trait?
- bnbwebexpertise/laravel-attachments 1.x-dev requires nesbot/carbon ~1.20 -> satisfiable by nesbot/carbon[1.20.0, 1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2].
Currently an issue when handling multiple database connections, to get the relationship working you need to specify connections on both models, even if one just takes the default connection by default.
Perhaps just a configurable option?
Is it possible to change the migration name
/migrations/2017_02_21_070324_alter_attachments_table_extend_filetype.php
It executes before then
/migrations/2017_02_21_070324_create_attachments_table.php
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.