Giter Site home page Giter Site logo

plank / laravel-mediable Goto Github PK

View Code? Open in Web Editor NEW
720.0 21.0 99.0 2.13 MB

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel

License: MIT License

PHP 100.00%
hacktoberfest laravel file-upload eloquent

laravel-mediable's People

Contributors

aalyusuf avatar abbasudo avatar anilkumarthakur60 avatar borisdamevin avatar boumanb avatar crishoj avatar cyrulik avatar dependabot[bot] avatar frasmage avatar geosot avatar hailwood avatar jason-nabooki avatar jdhmtl avatar johannesschobel avatar julesprimo avatar laravelfreelancernl avatar ls-sean-fraser avatar nadinengland avatar pet1330 avatar riesjart avatar riesjart2 avatar ryankilf avatar sebdesign avatar simonschaufi avatar sparclex avatar timacdonald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-mediable's Issues

Syntax error or access violation: 1071 Specified key was too long;

Getting the following error at the last step of installation when doing a php artisan migrate using Laravel 5.4.15, MySql 5.6, PHP 7.1.2

[Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `media` add unique `media_disk_directory_filename_extension_unique`(`disk`, `directory`, `filename`, `extension`))

  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

I already have the following set up in my AppServiceProvider.php:

use Illuminate\Support\Facades\Schema;

function boot()
{
    Schema::defaultStringLength(191);
}

Wrong media url generation.

Library generating wrong url for media files

It should generate url as http://localhost/mediable_test/public/storage/media/95510839133c8100288fbf061548acf3.jpg but it is generating http://localhost/mediable_test/public/storage/storage/media/95510839133c8100288fbf061548acf3.jpg.
uneccessary including two "storage" included in url.
my code is as
for adding media

$user = \App\User::first();
$defaultImage = new \Symfony\Component\HttpFoundation\File\File(storage_path("app/file.jpg"));
$thumbnail = \MediaUploader::fromSource($defaultImage)
            ->toDestination('public', 'media')
            ->useHashForFilename()->onDuplicateIncrement()
            ->upload();
$user->attachMedia($thumbnail, 'thumbnail');

and for getting url

$user = \App\User::first();
$thumbnail = $user->firstMedia('thumbnail');
$url = $thumbnail->getUrl();
//$url value coming as http://localhost/mediable_test/public/storage/storage/media/95510839133c8100288fbf061548acf3.jpg.

Using default filesystem config

Question about Postgres Support

Hello,

Thank you for this fantastic package!

I have run into a Sql Query exception and I am not sure if it is actually a bug or if I am doing something wrong on my end. When attempting to run $model->attachMedia($media, 'tag'); I get this error:

Illuminate\Database\QueryException with message 'SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "order"
LINE 1: select `tag`, max(`order`) as aggregate from "mediables" whe...
	^ (SQL: select `tag`, max(`order`) as aggregate from "mediables" where "mediable_type" = App\Author and "mediable_id" = 1 and "tag" in (headshot) group by "tag")'

This only happens when using Postgres; it works fine when I try it with Mysql. Am I doing something wrong?

ErrorException: Illegal offset type

laravel: 5.4
I have this code in my controller:

$media = null;
if ($request->hasFile('header_picture')) {            
	$media = MediaUploaderFacade::fromSource($request->file('header_picture'));
	$media
		->toDestination('public', Event::DIR_EVENT_HEADER_PICTURES)
		->upload();
}
$event = Event::create(...);
if (isset($media)) {
	$event->attachMedia($media, ['original']);
}

My problem is that the type of $media is NOT of type Media but of type MediaUploader and this crashes here: https://github.com/plank/laravel-mediable/blob/master/src/Mediable.php#L479 as it is trying to convert an object into an array.

Am I doing something wrong or is this a bug?

about the config on_duplicate

current the are three config for on_duplicate
the replace is first delete the finded record and then upload again

i just want return the find record,how to carray out this?

Lower case file extension - how?

I run into a duplicate entry error due of mixed file extensions (lower case vs. upper case):

If I upload an image on my iPhone, the file extension willl be ".JPG". If I upload the same image with lower case extension, the above error occurs.

Is there a way to "normalize" (i.e. lower case the extension) the filename to use?

Intervention Image

Hi,

Came across your package and I have to say it has been a time save when it comes to uploading media files for different models. Many thanks for that.

I have a small question, I am trying to generate thumbnail for images that are uploaded and the intervention image class is my go to class when resizing images. While I can write the code to generate the thumbnails to individual folders / disks, is there a way I can tap into this using your package?

For example when uploading files, the fromSource method is used. Is there a method that I can use to upload a generated thumbnail e.g MediaUploaded::fromFile($thumbnail)->upload(). $thumbnail coming from something like $thumbnail = Image::make('foo.jpg')->resize(300, 200);

Any thoughts would be great!

Thanks

Emmanuel

SourceAdapterFactory - Undefined variable: adapter

public function create($source)
    {
        if ($source instanceof SourceAdapterInterface) {
            return $source;
        } elseif (is_object($source)) {
            $adapter = $this->adaptClass($source);
        } elseif (is_string($source)) {
            $adapter = $this->adaptString($source);
        }

        if ($adapter) {
            return new $adapter($source);
        }

        throw MediaUploadException::unrecognizedSource($source);
    }

Planning for Next Major Version

Hello to all watchers and contributors (paging @sebdesign),

With the new year approaching, I think it is time to start planning the next major version of this package. Most pressingly, with PHP 5.6 passing into security-only support tomorrow night, I think it is time to drop support for PHP 5.x branch and fully embrace the new features of PHP 7.x. I will be working on this over the next few weeks, as I have time.

A new major version presents an opportunity to add any number of other changes that we want to the codebase. So I would like to ask if there are any new features that should be incorporated into the package at the same time. Is there anything that you would like to see built into the package? Are there any methods that should really be moved or renamed? Noticed any code smells that I overlooked? Now is the time to ask.

Feel free to make any suggestions in this thread. Pull Requests also very much welcome!

Call to undefined method move()

Hello!

Sorry for disturbing you with such a trivial matter and thanks in advance for all the hardwork put into this package. Maybe I am reading the documentation sideways, but ive tried everything to no avail.

Essentially I am trying to query Media::whereBasename('abc.jpg'); and then ->move('new_directory')

But I keep getting Call to undefined method move()

I am using:

use Plank\Mediable\Media;

What am I missing?

Chunke file uploads.

Hello guys. First, thanks for the package.
I'm interested if there is a way of chunked file upload. It is useful when you have realy large file and sometimes filesystem doesn't really want to work with large ones.

Intervention Image Integration

Planning to add support for Intervention manipulations while uploading images.

Currently considering an API like the following:

MediaUploader::fromSource('example.jpg')
    ->applyManipulations(function(Image $image) {
         $image->resize(300, null);
    }, $quality = null)
    ->upload()

Error with the "withFilename" method

Hi!

When I want to upload and change the file name with the "withFilename()" method, it throws me this error:

Call to undefined method Plank\Mediable\MediaUploader::withFilename()

Did I miss something? Some "use" or something else?

Exception Error While Importing Files

config/mediable

'default_disk' => 'uploads',
 'allowed_disks' => [
     'uploads',
 ],

File system:

  'uploads' => [
            'driver' => 'local',
            'root' => storage_path('app/uploads'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

Code to Import File

$disk=Storage::disk('local');
$path = 'uploads\about-img.jpg';
$media = MediaUploader::importPath($disk,$path);
dd($media->getUrl());

Error
image

error migrate in laravel 5.3

migrate in laravel 5.3 error use package

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table media add uniq
ue media_disk_directory_filename_extension_unique(disk, directory, filename, extension))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

Bad method call exception 'getForeignKey()' upon detaching media tags

Description

There is an issue with Plank\Mediable\Mediable::detachMediaTags() because it attempts to invoke an undefined method getForeignKey() which leads to error:
Call to undefined method Illuminate\Database\Query\Builder::getForeignKey().
This function is also called in vendor/plank/laravel-mediable/src/Mediable.php:79.

Potentially the other function should called instead: Illuminate\Database\Eloquent\Relations\BelongsToMany::getQualifiedForeignKeyName()

Versions

  • Laravel Framework 5.4.11
  • plank/laravel-mediable 2.4.1

getUrl() in Laravel 5.1 with latest version of laravel-mediable

When I run getUrl() function on Laravel 5.1 with local file-system and s3 as well I get following error.
$file_url = $media->getUrl();

BadMethodCallException in PluggableTrait.php line 85:
Call to undefined method League\Flysystem\Filesystem::url

Is there any previous version that will work fine with Laravel 5.1?

On replace media action, created_at date changes

Laravel 5.4, replace media, via config/mediable.php
'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_REPLACE,

From controller:
$media = MediaUploader::fromSource($file)->
toDestination('public', $path)->
upload();

I also tried forcing replace:
$media = MediaUploader::fromSource($file)->
toDestination('public', $path)->
onDuplicateReplace() ->
upload();

Either method, when file uploaded after first time, created_at value in database table media changes. Unless I am missing something, only updated_at should change?

Could not recognize source

Hi,

When I want upload a file, I have this error : Could not recognize source, 'poster_3_fury_road_mad_max_by_cesaria_yohann-d8rd450.jpg' provided.

My code, is the exemple code from documentation:

$media = MediaUploader::fromSource($request->input('media'))
    ->toDestination('public', 'thumbnails')
    ->upload();

One idea ?
Thank you.

getUrl for multiple media

hi
after attaching some media to a model how can I retrieve the media url
$files = $request->file('files');
foreach ($files as $file) {
$media = MediaUploader::fromSource($file)->upload();
$task->attachMedia($media,'image');
}

and here too
$tasks = Task::withMedia('image')->get();

Upload Base64

Hey @frasmage and community,

thank you very much for this awesome package. I really like the lightweight approach.
I have a question regarding the upload of files - i couldn't find anything in the docs about this issue:

In my API I upload the files via Base64 encoded strings. Is there a convenient way to automatically create a file based on the Base64 string of a file?!

Cheers and thank you!

Specified key was too long; max key length is 1000 bytes

I get this when running the migrations:

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table media add u
nique media_disk_directory_filename_extension_unique(disk, directory, filename, extension))

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

Something with this line;
$table->unique(['disk', 'directory', 'filename', 'extension']);

User-Media Relationship

Hi!

I'm building a media manager for a project where users can upload images and attach them to posts, and laravel-mediable is great for that requirement. However, is there a way for the users to see only their uploaded images?

What I was thinking is to modify the media table and add a foreign key to the users table. What I don't know is how to have the user_id inserted together with the rest of the media details.

Any suggestions on how to achieve this?

Thanks.

How to Check Duplicate Media ?

I have already uploaded files using elfinder. To link to db, I used MediaUploader::importPath.
But, when trying to associate the same file to another model or during model update, I am getting 'Duplicate Entry Error".

Tried but not working.

'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_REPLACE,
`

public function attachMedia($model, $filename,  $attribute) {
        $media = MediaUploader::importPath($this->disk, $filename);
        if ($model->hasMedia('featured')) {
            $model->syncMedia($media, [$attribute]);
        } else {
            $model->attachMedia($media, [$attribute]);
        }
    }

How can I check media existence before
$media = MediaUploader::importPath($this->disk, $path);

Error Undefined class constant 'ON_DUPLICATE_REPLACE'

I get the same error when using this command section

up class :

use MediaUploader;

use Plank\Mediable\Media;

$media = MediaUploader::fromSource($request->file('image'))
->setDirectory('/avatar/demo')
->setOnDuplicateBehavior(Media::ON_DUPLICATE_REPLACE)

->upload();

resuft => Undefined class constant 'ON_DUPLICATE_REPLACE'

File with whitespace in filename does not upload

Hey guys,

I try to upload files like this

$file2 = MediaUploader::fromSource(Input::file('file2'))->useHashForFilename()->toDestination('uploads', '')->upload();
$entry->attachMedia($file2, 'file2');

This works for files that have no whitespace. However when a file is named e.g. Bildschirmfoto 2016-12-28 um 15.25.17 it throws an error:

bildschirmfoto 2016-12-31 um 14 12 32

Non-static method

Hi,

I call package with use Plank\Mediable\MediaUploader;, but I have this error Non-static method Plank\Mediable\MediaUploader::fromSource().

One idea ?
Thank you.

how to set url path folder domain order

I'm working on 3 orther folder servers
Backend: domain a == api
frontend: domain b == call api
media : domain c ?


$media->getUrl(); // errors url

Help me !

Could not recognize source, `` provided.

Good morning to everybody, sorry for my English.
When i make a request the system answer the message in object. Input::file('file') it's the correct file. Why?

What's the best way to compress an image while uploading?

Hi,

First, I love this package - it's fantastic and very easy to use. But I'm a little bit confused about how to manipulate an image while uploading it (e.g. size it down to a max. resolution). I'm also using the very popular intervention image library, so this one can be used for the file compression.

So, what's the best way to do this?

I know, I could upload the file using the Image:Class of intervention and put the image string to the media class (fromString), but doing so I'll pass all the validation stuff supported by it.

Regards,
Marc

Call to a member function delete() on null

Hey,

I started using this cool package and faced with some problem, I sew in documentation that there is console command to add to database all files but I have not did it so I got error "Call to a member function delete() on null" in MediaUploader.php line 661

Its the error inside private function deleteExistingMedia(), current code is

Media::where('disk', $model->disk)
            ->where('directory', $model->directory)
            ->where('filename', $model->filename)
            ->where('extension', $model->extension)
            ->first()->delete(); 

It can be changed maybe this way

$media = Media::where('disk', $model->disk)
            ->where('directory', $model->directory)
            ->where('filename', $model->filename)
            ->where('extension', $model->extension)
            ->first();
if($media){
$media->delete();
}

to check for first if file is in database to not get such error

Regards,
Giorgi Chumburidze

How to replace the Media class with an own one?

Hi,

I've tryed to extend the Media class with an own one with more functionality (i.e. storing external meta data like the image auhor, ...). So I created a new class:

class MetaMedia extends Media

I've configured (mediable.php) it like:

'model' => \App\MetaMedia::class

After that, I got the following error:

Table 'xyz.meta_media' doesn't exist

So I've included the following line in my model:

protected $table = 'media';

After that, I got:

Column not found: 1054 Unknown column 'mediables.meta_media_id' in 'field list' (SQL: select media.*, mediables.mediable_id as pivot_mediable_id, mediables.meta_media_id as pivot_meta_media_id, mediables.tag as pivot_tag, ...

What to do now?

Regards,...

Get only one media

Hi,

I try to find a method to get only one media on posts collection and not all media attach on each post.

For exemple :

A post has many media, all with same tag. I wanna get only one of them. I suppose we need to use the join method, but how ?

Now a use $posts = Post::with('media')->get();, but I dont wanna all media.

Thank you.

Improvement to github readme/doc

Kindly attach the trait for the model as well in read me file here. Simply calling attachMedia() doesn't work.

class Post extends Model
{
use Mediable;

// ...

}

Mutator

Hi,

I do not put up a mutator to update the filename before the record in the database.

One can not use the mutators?

Thank you.

SQL Server support

Hi,

Following on from the Postgres support question, will this package work well with MS SQL server?

Thanks,

Nhg

Image Resizing/Manipulation support.

I was reading the Docs, and I found this to have many great features. One thing I didn't see, image manipulation, or at least image resizing to thumbnails, like what Wordpress do.

Intervention/image is a very nice image manipulation library. It would be great if it will be integrated with laravel-mediable.

MySQL Version Requirements?

Is there a minimum supported version of MySQL for this package? Running 5.6.28 I get the following error when attempting to attach a Mediable:

SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: select max(order) as aggregate from mediainner joinmediablesonmedia.id=mediables.media_idwheremediables.mediable_id= 3 andmediables.mediable_type= App\Tower andtag= thumbnail order byorder asc)

Create image duplicates and upload

Please give me example to upload new image with another sizes

                    if (!$user->hasMedia('avatar_' . $width . 'x' . $height)) {
                        $img = Image::make($user->firstMedia('avatar')->getUrl());
                        if ($crop) {
                            $img->fit($width, $height);
                        } else {
                            $img->resize($width, $height, function ($constraint) {
                                $constraint->aspectRatio();
                            });
                        }
                    }
                  $media = MediaUploader::fromSource($img)
                  ->useHashForFilename()
                  ->toDestination('cloud', 'user/avatars/thumb/')
                ->upload();


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.