PHP code example of ixudra / imageable

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

    

ixudra / imageable example snippets



    'providers'     => array(

        //...
        Ixudra\Imageable\ImageableServiceProvider::class,

    ),



    php artisan migrate --package="ixudra/imageable"



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

    }



    {!! Form::open(array('url' => 'cards', 'method' => 'POST', 'id' => 'createCard', 'class' => 'form-horizontal', 'role' => 'form', 'files' => true)) !!}

        <div class="well well-large">
            <div class='form-group {{ $errors->has('name') ? 'has-error' : '' }}'>
                {!! Form::label('name', 'Name:', array('class' => 'control-label col-lg-3')) !!}
                <div class="col-lg-6">
                    {!! Form::text('name', $input['name'], array('class' => 'form-control')) !!}
                    {!! $errors->first('name', '<span class="help-block">:message</span>') !!}
                </div>
            </div>
        </div>

        @


    <div class="row">
        <div class="well well-large col-md-12">
            <div class='col-md-10'>
                <div class='col-md-4'>Name:</div>
                <div class='col-md-8'>{{ $card->name }}</div>
            </div>
        </div>
    </div>

    @