在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):CodeSleeve/laravel-stapler开源软件地址(OpenSource Url):https://github.com/CodeSleeve/laravel-stapler开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):laravel-staplerLaravel-Stapler is a Stapler-based file upload package for the Laravel framework. It provides a full set of Laravel commands, a migration generator, and a cascading package config on top of the Stapler package. It also bootstraps Stapler with very sensible defaults for use with Laravel. If you are wanting to use Stapler with Laravel, it is strongly recommended that you use this package to do so. Laravel-Stapler was created by Travis Bennett.
RequirementsThis package currently requires php >= 5.4 as well as Laravel >= 4, up to 5.4 (5.4 is the last version of Laravel this package will officially support). Due to the recent inconsistencies/changes introduced into Eloquent and the fact that Laravel now ships with Disks/Flysystem support, I have decided not to try and maintain this package for future version of Laravel. I am not adding a hard requirement for Laravel <= 5.4 due to the fact that some folks are already using it in their Laravel > 5.4 projects. If you want use this package in new version of Laravel you may do so at your own risk. If you're going to be performing image processing as part of your file upload, you'll also need GD, Gmagick, or Imagick (your preference) installed as part of your php environment. InstallationLaravel-Stapler is distributed as a composer package, which is how it should be used in your app. Install the package using Composer. Edit your project's "require": {
"laravel/framework": "4.*",
"codesleeve/laravel-stapler": "1.0.*"
} Once this operation completes, the final step is to add the service provider. For Laravel 4, Open 'Codesleeve\LaravelStapler\Providers\L4ServiceProvider' For Laravel 5, Open 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' DeprecationsAs of 1.0.04, the 'Codesleeve\LaravelStapler\LaravelStaplerServiceProvider' service provider has been deprecated (this provider will be removed in the next major release). Instead, you should now be using the corresponding service provider for the specific version of Laravel that you're using. migrating-from-Stapler-v1.0.0-Beta4If you've been using Stapler (prior to v1.0.0-Beta4) in your Laravel app, you now need to be using this package instead. Uninstall Stapler (remove it from your composer.json, remove the service provider, etc) and install this package following the instructions above. Once installed, the following changes may need need to be made in your application:
QuickstartIn the document root of your application (most likely the public folder), create a folder named system and
grant your application write permissions to it. For this, we're assuming the existence of an existing In your model: 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);
}
}
From the command line, use the migration generator: php artisan stapler:fasten users avatar
php artisan migrate In your new view: <?= Form::open(['url' => action('UsersController@store'), 'method' => 'POST', 'files' => true]) ?>
<?= Form::input('first_name') ?>
<?= Form::input('last_name') ?>
<?= Form::file('avatar') ?>
<?= Form::submit('save') ?>
<?= Form::close() ?> In your controller: 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());
} In your show view: <img src="<?= $user->avatar->url() ?>" >
<img src="<?= $user->avatar->url('medium') ?>" >
<img src="<?= $user->avatar->url('thumb') ?>" > To detach (reset) a file, simply assign the constant STAPLER_NULL to the attachment and the save): $user->avatar = STAPLER_NULL;
$user->save(); This will ensure the the corresponding attachment fields in the database table record are cleared and the current file is removed from storage. The database table record itself will not be destroyed and can be used normally (or even assigned a new file upload) as needed. CommandsfastenThis package provides a In the quickstart example above, calling
refreshThe Reprocess all attachments for the ProfilePicture model:
Reprocess only the photo attachment on the ProfilePicture model:
Reprocess a list of attachments on the ProfilePicture model:
TroubleshootingBefore you submit an issue or create a pull request, please take a look at the Troubleshooting Section section of the Stapler package. There's a very good chance that many (if not all) of the issues you're having with this package are related to the base stapler package and have already been addressed there. ContributingThis package is always open to contributions:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论