getHash() public static method

Get a unique hash from a file path.
public static getHash ( string $path ) : string
$path string
return string
 /**
  * Register any other events for your application.
  *
  * @param \Illuminate\Contracts\Events\Dispatcher $events
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     // Generate a unique hash for a song from its path to be the ID
     Song::creating(function ($song) {
         $song->id = File::getHash($song->path);
     });
     // Remove the cover file if the album is deleted
     Album::deleted(function ($album) {
         if ($album->hasCover) {
             @unlink(app()->publicPath() . '/public/img/covers/' . $album->cover);
         }
     });
 }
Example #2
0
 /**
  * Generate a unique hash for a file path.
  *
  * @param $path
  *
  * @return string
  */
 public function getHash($path)
 {
     return File::getHash($path);
 }
Example #3
0
 /**
  * Get a Song record using its path.
  *
  * @param string $path
  *
  * @return Song|null
  */
 public static function byPath($path)
 {
     return self::find(File::getHash($path));
 }