我在我的控制器中加入了两个桌子-- thought_journal_entries和emotions。他们之间有着多到多的关系,这种关系已经加入到了模型中。
我相信我的代码会起作用,但我得到了错误:
格式错误的UTF-8字符,可能编码错误.
我想我的代码就快到了,我只是不确定我是否正确地循环以获得emotion->image字段
$user_id = auth()->user()->id;
$thought_journal_entries = ThoughtJournalEntry::with('emotions')->where('user_id', $user_id)->orderBy('created_at', 'desc')->paginate(15);
foreach($thought_journal_entries as $thought_journal_entry) {
foreach($thought_journal_entry->$emotions as $emotion) {
$emotion->image = 'data:image/jpeg;base64,' . base64_encode( $emotion->image);
}
}
return $thought_journal_entries;发布于 2020-03-03 17:24:27
utf8_unicode_ci。检查config/database.php文件:‘'charset’=>‘UTF 8’,‘=>’UTF 8_unicode_ci‘,
utf8,而MySQL的utf8mb4是更好的
。
https://stackoverflow.com/questions/60512426
复制相似问题