Laravel Image Storage: Store and retrieve images in Laravel models

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2020-10-31 (0 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 43 All time: 10,180 This week: 243Up
Version License PHP version Categories
laravel-has-images 1.0.0MIT/X Consortium ...5PHP 5, Graphics, Files and Folders, D...
Description Author

This package can store and retrieve images in Laravel models.

It provides a trait that can be used to associate image files to a given model class that uses that trait.

The trait provides functions to create, retrieve, update and delete multiple images to one model object.

Innovation Award
PHP Programming Innovation award nominee
October 2020
Number 3
Many applications that use the Laravel framework need to implement object models to store certain property data and can be associated to one or more pictures.

This package simplifies the implementation of such types of Laravel models by providing a trait that implements many types of operations to manipulate images files to be associated with each model object.

Manuel Lemos
Picture of Moamen Eltouny
  Performance   Level  
Name: Moamen Eltouny <contact>
Classes: 32 packages by
Country: Egypt Egypt
Age: 28
All time rank: 286429 in Egypt Egypt
Week rank: 42 Up2 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 17x


<p align="center"><a href="" target="_blank"><img src="" width="470"></a></p>

<p align="center"> <a href="" target="_blank"><img src="" alt="Source"></a> <a href="" target="_blank"><img src="" alt="Packagist Version"></a><br> <a href="" target="_blank"><img src=">=6.0-red.svg?style=flat-square" alt="Laravel"></a> <img src="" alt="Packagist Downloads"> <img src="" alt="Source"> </p>

Laravel images provides a quick and easy way to link images with a model.


Install the latest version using Composer:

$ composer require pharaonic/laravel-has-images

then publish the migration & config images

# if you didn't publish Pharaonic\laravel-uploader before.

$ php artisan vendor:publish --tag=laravel-uploader

$ php artisan vendor:publish --tag=laravel-has-images
$ php artisan migrate


<a name="INC"></a>

Including it in a Model

// An example
// Using HasImages in Article Model
use Pharaonic\Laravel\Images\HasImages;
use Pharaonic\Laravel\Helpers\Traits\HasCustomAttributes;

class Article extends Model
    use HasCustomAttributes, HasImages;

<a name="HTU"></a>

How to use

$article = Article::find(1); 					// Model
$images = $article->images // Article Images
$article->addImage($request->fileName);	// Setting New Single Image

echo $article->images[0]->url; 	        // Getting image URL

// Create Article
$article = new Article;
$article->images = [							// Setting Images List

echo $article->images[2]->url;

// Delete Images
$article->delete(); 				// Delete Article with all related images
// OR
$article->clearImages();			// Delete all related images
// OR
$article->images[2]->delete();	// Delete image with Index

<a name="UP"></a>

Uploader Options

$article->images[index number] is retrieving Uploader Object.

That's allow for us use all Pharaonic/laravel-uploader options.

$image = $article->images[0];
// Information
echo $image->hash; // Image's Hash
echo $image->name; // Image's Name
echo $image->path; // Image's Path
echo $image->size; // Image's Size in Bytes
echo $image->readableSize(); // Image's Readable Size B, KB, MB, ...
echo $image->readableSize(false); // Image's Readable Size B, KiB, MiB, ...
echo $image->extension; // Image's Extension
echo $image->mime; // Image's MIME

echo $image->visits; // Image's visits (Visitable Image)

// Getting URL
echo $image->url; // Getting Uploaded Image's URL

// Deleting The Image

// Permits (Private Image)
$permits = $image->permits; // Getting Permits List
$permitted = $image->isPermitted($user); // Checking if permitted (App\User)

$image->permit($user, '2021-02-01'); // Permitting a user
$image->forbid($user); // Forbidding a user


MIT license

  Files folder image Files  
File Role Description
Files folder imagesrc (3 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagedatabase (1 directory)
  Plain text file HasImages.php Class Class source
  Plain text file Image.php Class Class source
  Plain text file ImagesServiceProvider.php Class Class source

  Files folder image Files  /  src  /  database  
File Role Description
Files folder imagemigrations (1 file)

  Files folder image Files  /  src  /  database  /  migrations  
File Role Description
  Plain text file images.stub Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:10,180
This week:243Up
For more information send a message to info at phpclasses dot org.