laravel5-retrieving blob file返回true或1

jm81lzqq  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(538)

我正在努力从数据库中检索blob值。每次我用这种东西 {{$record->taccuino_report_posteriore }} 在foreach中,为了获取其值,它只返回1,或者如果我读取了对象的json,则该值设置为true。我真正需要的是把它的实际值作为字符串,而不是true或1。事实上,同样的事情也发生了,从斑点变成了长线。
另外,我确信存储的实际值不仅仅是1或true,因为我已经使用mysql检查了真正的“string”值。
更新
迁移

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTblTaccuinoTable extends Migration
{
/**
 * Schema table name to migrate
 * @var string
 */
public $set_schema_table = 'tbl_taccuino';

/**
 * Run the migrations.
 * @table tbl_taccuino
 *
 * @return void
 */
public function up()
{
    if (Schema::hasTable($this->set_schema_table)) return;
    Schema::create($this->set_schema_table, function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id_taccuino');
        $table->integer('id_paziente')->unsigned();
        $table->string('taccuino_descrizione', 45);
        $table->date('taccuino_data');
        $table->binary('taccuino_report_anteriore');
        $table->binary('taccuino_report_posteriore');

        $table->index(["id_paziente"], 'fk_tbl_taccuino_tbl_pazienti1_idx');

        $table->foreign('id_paziente', 'fk_tbl_taccuino_tbl_pazienti1_idx')
            ->references('id_paziente')->on('tbl_pazienti')
            ->onDelete('no action')
            ->onUpdate('no action');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
 public function down()
 {
   Schema::dropIfExists($this->set_schema_table);
 }
}

模型

<?php

/**

* Created by Reliese Model.
* Date: Mon, 25 Dec 2017 12:47:05 +0000.
* /

namespace App\Models\Patient;

use Reliese\Database\Eloquent\Model as Eloquent;

/**
 * Class Taccuino
 * 
 * @property int $id_taccuino
 * @property int $id_paziente
 * @property string $taccuino_descrizione
 * @property \Carbon\Carbon $taccuino_data
 * @property boolean $taccuino_report_anteriore
 * @property boolean $taccuino_report_posteriore
 * 
 * @property \App\Models\Pazienti $tbl_pazienti
 *
 * @package App\Models
 */
class Taccuino extends Eloquent
{
protected $table = 'tbl_taccuino';
protected $primaryKey = 'id_taccuino';
public $incrementing = false;
public $timestamps = false;

protected $casts = [
    'id_taccuino' => 'int',
    'id_paziente' => 'int',
    'taccuino_report_anteriore' => 'boolean',
    'taccuino_report_posteriore' => 'boolean'
];

protected $dates = [
    'taccuino_data'
];

protected $fillable = [
    'id_paziente',
    'taccuino_descrizione',
    'taccuino_data',
    'taccuino_report_anteriore',
    'taccuino_report_posteriore'
];

public function tbl_pazienti()
{
    return $this->belongsTo(\App\Models\Patient\Pazienti::class, 'id_paziente');
}
}
oxcyiej7

oxcyiej71#

您需要删除此行才能使其正常工作:

'taccuino_report_posteriore' => 'boolean'

https://laravel.com/docs/5.5/eloquent-mutators#attribute-铸造

相关问题