我要在控制器中加入两个表-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;
答案 0 :(得分:0)
将数据库文件配置为sqldf::sqldf("select count(*) as n from mayorsDF where FullName is null")
# n
# 1 36
allNamesDF <- sqldf::sqldf("select distinct FullName from mayorsDF")
anyNA(allNamesDF)
# [1] TRUE
sum(is.na(allNamesDF))
# [1] 1
length(unique(allNamesDF[!is.na(allNamesDF)]))
# [1] 1406
。检查文件config / database.php:
utf8_unicode_ci
确保将Mysql数据库设置为'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
,而MySQL的utf8
更好
确保将文件字符设置为UTF-8,且不使用BOM(字节顺序标记)