我正在尝试按照 Laravel 教程使用 Eloquent 在我的数据库中映射现有的一对一关系,但我收到了一个字符串转换错误。
我必须使用其他程序使用的现有数据库,因此我无法更改数据库结构。
这是我的模型:
佩索阿.php
namespace App\Models;
use Illuminate\Support\Facades\Log; use
Illuminate\Database\Eloquent\Model;
class Pessoa extends Model {
protected $table = 'pessoas';
public function estadoCivil(){
//return EstadoCivil::find($this->estado_civil_id);
return $this->hasOne('App\Models\EstadoCivil', 'estado_civil_id');
}
}
Run Code Online (Sandbox Code Playgroud)
EstadoCivil.php 命名空间 App\Models;
use Illuminate\Database\Eloquent\Model;
class EstadoCivil extends Model
{
protected $table = 'estados_civis';
}
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办,但我收到此错误:
类 Illuminate\Database\Eloquent\Relations\HasOne 的对象无法转换为字符串
我搜索了拼写错误和其他错误,但一无所获。我什至没有尝试将任何内容转换为字符串来获取此错误,数据库中 id 和外键的类型也是相同的。
这是使用它的控制器:
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Pessoa as Pessoa;
class Eu extends Controller
{
public function __construct()
{
}
public function dadosCompletos(Request $request){ …Run Code Online (Sandbox Code Playgroud) 我的项目运行正常,唯一的问题是搜索是否区分大小写。它可以很好地搜索子字符串,但是如果我输入“ Test”,它将忽略“ test”作为有效结果。
我正在使用pouchdb-find来使搜索更容易,并且与混浊搜索和限制/跳过分页参数更加相关。
我正在使用ion-searchbar为用户键入查询的字符串。
这是我的控制器代码节选:
@Component({
selector: 'page-notas',
templateUrl: 'notas.html'
})
export class NotasPage {
notas: Array<Object> = [];
zone: any = new NgZone({ enableLongStackTrace: false });
db: any = new PouchDB('banco_de_dados.bd');
db_limit = 10;
pouch_query: object = {
selector: { data_emissao: { $gt: null } },
sort: [ {'data_emissao' : 'desc'} ],
limit: 10,
skip: 0,
};
constructor(
private scanner: BarcodeScanner,
private toastCtrl: ToastController,
private googleAnalytics: GoogleAnalytics,
public …Run Code Online (Sandbox Code Playgroud)