msieprawski/eloquent-photos

Photos for Laravel models
19 1
Install
composer require msieprawski/eloquent-photos
Latest Version:0.1
License:MIT
Last Updated:Feb 25, 2017
Links: GitHub  ·  Packagist
Maintainer: msieprawski

Eloquent Photos

About

This package has been created for everyone which has photos related to any eloquent models in projects.

Compatibility

Currently this package has been tested and developed for Laravel 5.3 or greater.

Installation

  1. composer require msieprawski/eloquent-photos
  2. Add package service provider in your config/app.php file: Msieprawski\EloquentPhotos\EloquentPhotosServiceProvider::class,
  3. Publish migrations and run php artisan migrate: php artisan vendor:publish --tag=migrations
  4. Add HasPhotos trait to your model: use Msieprawski\EloquentPhotos\HasPhotos
  5. Add protected property to your model with directory name where photos should be stored: protected $targetPhotosDirectory = 'users';

Usage

Add photos to your model

<?php namespace App;
$user = User::find(1);
$user->addPhoto('/path/to/your/photo.jpg');
$user->addPhotos([
    '/path/to/your/photo1.jpg',
    '/path/to/your/photo2.jpg',
]);

Add uploaded photos to your model

<?php namespace App;

$photos = request()->file('photos');
$user = User::find(1);
$user->addPhoto($photos);

It will automatically upload the photos and store it against user entity.

Get photos

<?php namespace App;
$user = User::find(1);
$photos = $user->photos;
foreach ($photos as $photo) {
    /** @var Msieprawski\EloquentPhotos\Photo $photo */
    echo $photo->photo_path;
}

Delete photos

<?php namespace App;
$user = User::find(1);
$user->destroyPhotos();

License

Licensed under the MIT License

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

634,760,849 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

493,838,477 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

408,553,772 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

387,976,821 4,658