25/02
2017
Photos for Laravel models
This package has been created for everyone which has photos related to any eloquent models in projects., (*1)
Currently this package has been tested and developed for Laravel 5.3 or greater., (*2)
composer require msieprawski/eloquent-photos
config/app.php
file:
Msieprawski\EloquentPhotos\EloquentPhotosServiceProvider::class,
php artisan migrate
:
php artisan vendor:publish --tag=migrations
use Msieprawski\EloquentPhotos\HasPhotos
protected $targetPhotosDirectory = 'users';
<?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', ]);
<?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., (*3)
<?php namespace App; $user = User::find(1); $photos = $user->photos; foreach ($photos as $photo) { /** @var Msieprawski\EloquentPhotos\Photo $photo */ echo $photo->photo_path; }
<?php namespace App; $user = User::find(1); $user->destroyPhotos();
Licensed under the MIT License, (*4)