devfactorych / media Goto Github PK
View Code? Open in Web Editor NEWLaravel 4/5 package that saves uploaded files and links them with the associated model
License: MIT License
Laravel 4/5 package that saves uploaded files and links them with the associated model
License: MIT License
public function deleteMedia($group = null)
{
$media = $this->getMedia($group);
$count = 0;
foreach($media as $item)
{
$count += $this->removeMedia($item); //method removeMedia return null (void);
}
return $count;
}
It works just cause of pure accident )
You should rewrite it by something like:
$count ++;
if($this->removeMedia($item)) $count++;
and return bool from removeMedia() method;
this is what u need:
public function getUrlAttribute() {
return Illuminate\Support\Facades\URL::asset(\Config::get('media.config.files_directory') . $this->filename);
}
and this is what u got:
public function getUrlAttribute() {
return \Url::asset(\Config::get('media::files_directory') . $this->filename);
}
I do not have \Url class, and u do not publish config with name "media" but with name "media.config"
*I use lara 5.1
Temp Solution for those who got this bug to:
public function getUrlAttribute() {
return Illuminate\Support\Facades\URL::asset(Illuminate\Support\Facades\Config::get('media.config.files_directory') . $this->filename);
}
public function media() {
return $this->morphMany(YourModelMedia::class, 'mediable');
}
$this->public_path, $this->files_directory variable can not be found.
As a temporary solution
private function removeMedia($media) {
$this->public_path = rtrim(config('media.config.public_path'), '/') . '/';
$this->files_directory = rtrim(ltrim(config('media.config.files_directory'), '/'), '/') . '/';
File::delete($this->public_path . $this->files_directory . $media->filename);
$media->delete();
}
When running composer update
, the latest version of Composer now throws a warning:
Warning: Ambiguous class resolution, "CreateMediaTable" was found in both "$baseDir . '/database/migrations/2014_11_11_110645_create_media_table.php" and "/var/www/oar/vendor/devfactory/media/src/migrations/2014_11_11_110645_create_media_table.php", the first will be used.
Warning: Ambiguous class resolution, "UpdateNameAltTitleInMediaTable" was found in both "$baseDir . '/database/migrations/2015_03_26_135428_update_name_alt_title_in_media_table.php" and "/var/www/oar/vendor/devfactory/media/src/migrations/2015_03_26_135428_update_name_alt_title_in_media_table.php", the first will be used.
Could u please to add simple md5() renaming without part of original name?
And it will be nice to store files to subdirectories in this case, like /public/de/ad/be/ef/12/bb/ce/ed/deadbeef12bbceed.jpg
for example.
Hi, I am looking to rename the uploaded file. Can you guide me how can I do it?
The 2015_03_26_135428_update_name_alt_title_in_media_table
migration would be boken in sqlite
because sql query is not supported.
I think using doctrine/dbal
and update code be made compatible with other databases
Schema::table('media', function(Blueprint $table) {
$table->string('name')->nullable()->change();
$table->string('alt')->nullable()->change();
$table->string('title')->nullable()->change();
});
I think you should to add method ->getPath(), instead of using something like this:
File::delete($this->public_path . $this->files_directory . $media->filename);
Ok, i got collection of media by $model->getMedia('group');
Ok, i got an item by this code:
//i use first() but this is a single item. there's no any other files in this group for my model
$model->getMedia('group')->first();
So, how can i get full path to use in Form::image() ?
Should i always construct path manually by $this->public_path . $this->files_directory . $media->filename
? This is ridiculous, imho. Don't u think so?
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.