Laravel File Model: Add support for file properties in Laravel models

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2020-08-05 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 33 This week: 16All time: 9,981 This week: 14Up
Version License PHP version Categories
laravel-files 1.0MIT/X Consortium ...7PHP 5, Files and Folders, Libraries, D...
Description Author

This package can add support for file properties in Laravel models.

It provides a trait that can be used in model classes used in Laravel based applications, so model attributes can be used to store and retrieve data from files.

The package allows model classes to store data from files uploaded to Web server, serve stored data as files for download and delete model data.

Innovation Award
PHP Programming Innovation award nominee
August 2020
Number 3
Usually model classes are used to store and retrieve application objects in database tables.

However, for object variables that can contain data that maybe large, it may be better to use files to store the values of those values in files.

This way, the database table records do not become too large, thus avoiding to slow down the database access.

This package implements a trait to use with model classes based on the Laravel framework to make some of the model class objects be mapped to files.

Manuel Lemos
Picture of Moamen Eltouny
  Performance   Level  
Name: Moamen Eltouny <contact>
Classes: 11 packages by
Country: Egypt Egypt
Age: 27
All time rank: 357940 in Egypt Egypt
Week rank: 17 Up1 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 6x

Details

[RaggiTech] Laravel >= 6.0 - Model Files.

Latest Stable Version Total Downloads License

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

Install

Install the latest version using Composer:

$ composer require raggitech/laravel-files

then publish the migration & config files

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

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

$ php artisan vendor:publish --tag=laravel-files
$ php artisan migrate

Usage

<a name="config"></a>

Configuration

/
*	config/RaggiTech/files.php
*	default files fields
*
*	files 		=> ['image', 'picture', 'cover', 'thumbnail', 'video', 'audio', 'file']
*/

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

Including it in a Model

// An example
// Using HasFiles in Person Model
...
use RaggiTech\Laravel\Files\HasFiles;
use RaggiTech\Laravel\Helpers\Traits\HasCustomAttributes;

class Person extends Model
{
    use HasCustomAttributes, HasFiles;
    
    protected $filesAttributes  = ['passport']; // if not in defaults in config file
    
    protected $filesOptions 	= [ // optional
        'passport'	=> [
            'private'	=> true,
            // 'visitable'	=> true,
            'directory'	=> '/papers/passports'
        ]
    ];
    ...
}

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

How to use

$person = Person::find(1); 		        // Model

$person->passport = $request->myFile;   // Request Input File + Uploading it

echo $person->passport->url(); 	        // Getting passport file URL

// Delete Files
$person->delete(); 				// Delete Person with all related files
// OR
$person->clearFiles();			// Delete all related files
// OR
$person->passport->delete();	// Delete file

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

Uploader Options

$person->passport is retrieving Uploader Object.

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

$file = $person->passport;
// Information
echo $file->hash; // File's Hash
echo $file->name; // File's Name
echo $file->path; // File's Path
echo $file->size; // File's Size in Bytes
echo $file->readableSize(); // File's Readable Size B, KB, MB, ...
echo $file->readableSize(false); // File's Readable Size B, KiB, MiB, ...
echo $file->extension; // File's Extension
echo $file->mime; // File's MIME

echo $file->visits; // File's visits (Visitable File)


// Getting URL
echo $file->url(); // Getting Uploaded File's URL


// Deleting The File
$file->delete();


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

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

License

MIT license

  Files folder image Files  
File Role Description
Files folder imagesrc (3 files, 2 directories)
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 imageconfig (1 file)
Files folder imagedatabase (1 directory)
  Plain text file File.php Class Class source
  Plain text file FilesServiceProvider.php Class Class source
  Plain text file HasFiles.php Class Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Accessible without login Plain text file files.php Aux. Auxiliary script

  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 files.stub Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:33
This week:16
All time:9,981
This week:14Up

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