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 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 32 This week: 2All time: 10,045 This week: 90Up
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: 14 packages by
Country: Egypt Egypt
Innovation award
Innovation award
Nominee: 8x

 

Details

<p align="center"><a href="https://pharaonic.io" target="_blank"><img src="https://raw.githubusercontent.com/Pharaonic/logos/main/has-images.jpg" width="470"></a></p>

<p align="center"> <a href="https://github.com/Pharaonic/laravel-has-images" target="_blank"><img src="http://img.shields.io/badge/source-pharaonic/laravel--has--images-blue.svg?style=flat-square" alt="Source"></a> <a href="https://packagist.org/packages/pharaonic/laravel-has-images" target="_blank"><img src="https://img.shields.io/packagist/v/pharaonic/laravel-has-images?style=flat-square" alt="Packagist Version"></a><br> <a href="https://laravel.com" target="_blank"><img src="https://img.shields.io/badge/Laravel->=6.0-red.svg?style=flat-square" alt="Laravel"></a> <img src="https://img.shields.io/packagist/dt/pharaonic/laravel-has-images?style=flat-square" alt="Packagist Downloads"> <img src="http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Source"> </p>

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

Install

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

Usage

<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
	$request->file1,
	$request->file2,
	$request->file3
];
$article->save();

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
$image->delete();


// 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

License

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 README.md 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  
 100%
Total:32
This week:2
All time:10,045
This week:90Up

For more information send a message to info at phpclasses dot org.