【发布时间】:2021-09-18 15:44:02
【问题描述】:
我想选择MaxFileSize列中的值,同一张表中FileType列的值等于$fileType。也就是说,在这个例子中,如果我输入的 uploadType 是 mp4 ,我需要得到结果(即 $maxSize )为 6。
$fileType=$request->uploadType;
$maxSize = Filesizes::where('FileType',$fileType)->get(['MaxFileSize']);
我已尝试上述代码,但无法使用此代码获得我想要的结果。请帮助我提出您的建议。
文件大小表
| MaxFileSize | FileType |
|---|---|
| 6 | mp4 |
上面的代码给出了这样的输出:
Illuminate\Database\Eloquent\Collection {#1313
#items: array:1 [
0 => App\Models\Filesizes {#1314
#table: "filesizes"
#fillable: array:1 [
0 => "MaxFileSize"
]
#connection: "pgsql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:1 [
"MaxFileSize" => 6
]
#original: array:1 [
"MaxFileSize" => 6
]
#changes: []
#casts: array:1 [
"deleted_at" => "datetime"
]
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [
0 => "*"
]
#forceDeleting: false
}
]
}
【问题讨论】:
-
什么是错误和你想要实现什么。所以有人可以帮助你
-
@JohnLobo 请查看更新后的问题。我已经添加了我正在输入的输出。对于我给出的示例,如果我输入的
uploadType是 mp4 ,我需要得到结果(即$maxSize)为 6。 -
$maxSize = Filesizes::where('FileType',$fileType)->get(['MaxFileSize','FileType']);
-
如果你想读取格式然后 dd($maxSize->toArray());
-
@JohnLobo 我试过这个 -
dd($maxSize->toArray());。但它显示了这样的输出 -array:1 [ 0 => array:1 [ "MaxFileSize" => 6 ] ]。但是,我需要的输出只是 6。
标签: database laravel postgresql laravel-8 rest