PHP code example of cyneek / laravel-multiple-stapler

1. Go to this page and download the library: Download cyneek/laravel-multiple-stapler 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/ */

    

cyneek / laravel-multiple-stapler example snippets


Codesleeve\LaravelStapler\Providers\L5ServiceProvider::class,
Cyneek\LaravelMultipleStapler\Providers\LaravelMultipleStaplerProvider::class

php artisan migrate

class Example extends \Eloquent
{
    use MultipleFileTrait;

    function __construct(array $attributes = [] )
    {

        $this->hasOneAttachedFile('avatar', [
            'styles' => [
                'medium' => '300x300',
                'thumb' => '100x100'
            ]
        ]);
        
        parent::__construct($attributes);

    }

class Example extends \Eloquent
{
    use MultipleFileTrait;

    function __construct(array $attributes = [] )
    {

        $this->hasMultipleAttachedFiles('images', [
            'styles' => [
                'medium' => '300x300',
                'thumb' => '100x100'
            ]
        ]);
        
        parent::__construct($attributes);

    }


<?= Form::open(['url' => action('ExampleController@store'), 'method' => 'POST', 'files' => true]) 


public function store()
{
    // Create and save a new Example object, mass assigning all of the input fields (including the 'avatar' file field).
    $example = Example::create(Input::all());
}



<?= Form::open(['url' => action('ExampleController@storeMultiple'), 'method' => 'POST', 'files' => true]) 


public function storeMultiple()
{
    // Create and save a new Example object, mass assigning all of the input fields (including the 'avatar' file field).
    $example = Example::create(Input::all());
}


    $example = Example::find(1);
   
    $example->avatar->createdAt();


    $example = Example::find(1);
   
    foreach ($example->avatar as $avatar)
    {
        echo $avatar->file->createdAt();
    }



    Example::delete(1);



    $example->avatar()->delete();



    foreach ($example->avatar as $avatar)
    {
        echo $avatar->delete();
    }