1. Go to this page and download the library: Download ixudra/imageable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Publish all resources from all packages
php artisan vendor:publish
// Publish only the resources of the package
php artisan vendor:publish --provider="Ixudra\\Imageable\\ImageableServiceProvider"
use Ixudra\Imageable\Models\Image;
use Ixudra\Imageable\Traits\ImageableTrait;
class Card extends Eloquent {
use ImageableTrait;
protected $imagePath = 'images/cards';
public function image()
{
return $this->morphOne( Image::class, 'imageable' );
}
public function delete()
{
$this->image->delete();
parent::delete();
}
}
use Ixudra\Imageable\Services\Factories\ImageFactory;
class CardFactory {
protected $imageFactory;
public function __construct(ImageFactory $imageFactory)
{
$this->imageFactory = $imageFactory;
}
public function create($input, $prefix = '')
{
$card = Card::create( array( 'name' => $input['name'] ) );
$this->imageFactory->make( $input, $card, $prefix );
return $card;
}
public function modify($card, $input, $prefix = '')
{
$card = $card->update( array( 'name' => $input['name'] ) );
$this->imageFactory->modify( $card->image, $input, $card, $prefix );
return $card;
}
}