PHP code example of codesleeve / laravel-stapler

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

    

codesleeve / laravel-stapler example snippets


    'Codesleeve\LaravelStapler\Providers\L4ServiceProvider'

    'Codesleeve\LaravelStapler\Providers\L5ServiceProvider'

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;

class User extends Eloquent implements StaplerableInterface {
	use EloquentTrait;

	// Add the 'avatar' attachment to the fillable array so that it's mass-assignable on this model.
	protected $fillable = ['avatar', 'first_name', 'last_name'];

	public function __construct(array $attributes = array()) {
		$this->hasAttachedFile('avatar', [
			'styles' => [
				'medium' => '300x300',
				'thumb' => '100x100'
			]
		]);

		parent::__construct($attributes);
	}
}

php artisan stapler:fasten users avatar
php artisan migrate

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

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

<img src="<?= $user->avatar->url() 

$user->avatar = STAPLER_NULL;
$user->save();