ooxif / laravel-query-param
此包已被弃用,不再维护。未建议替代包。
以正确的方式处理Laravel数据库系统(Eloquent)中的二进制数据
1.0.3
2016-06-15 06:07 UTC
Requires
- php: >=5.4.0
- illuminate/database: 5.0.*||5.1.*||5.2.*
Suggests
- ooxif/laravel-spec-schema: Extends Laravel's Schema/Grammar/Blueprint to describe drivers' specific features
This package is not auto-updated.
Last update: 2024-07-06 16:28:07 UTC
README
laravel-query-param
laravel-query-param如何处理二进制数据。
laravel-query-param的作用
Laravel使用PDO & PDOStatement,将参数传递给PDOStatement::execute()。
PDOStatement::execute()将所有参数视为PDO::PARAM_STR,这破坏了一些二进制数据。
laravel-query-param
覆盖PDOStatement::execute()以将二进制数据视为PDO::PARAM_LOB。
安装
composer require "ooxif/laravel-query-param:1.0.*"
然后将'Ooxif\LaravelQueryParam\QueryParamServiceProvider',
添加到config/app.php
中的providers
。
示例
// table contains a binary column Schema::create('images', function ($table) { $table->increments(); $table->timestamps(); $table->binary('data'); }); // use ModelTrait, add '(column name)' => 'binary' to $casts class Image extends Eloquent { use Ooxif\LaravelQueryParam\ModelTrait; protected $table = 'images'; protected $casts = [ 'data' => 'binary', ]; } $lob = 'some binary data'; $image = new Image(); // setting/getting $image->data = $lob; $image->data; // object(Ooxif\LaravelQueryParam\Param\ParamLob) $image->data->value() === $lob; // true // saving $image->save(); // querying (model) - use param_lob() $image = Image::where('data', param_lob($lob))->first(); // querying (db) - use param_lob() $result = DB::table('images')->where('data', param_lob($lob))->first(); $result->data === $lob; // true