拜托,我正在写一个函数,我需要指导
function($file_name='*'){
File::where('filename',$file_name)->get();
}
我希望文件名在未定义文件名时拉出数据库表中的所有文件名列,如果是,则应使用该值来提取正确的数据。
我的问题是,我应该在函数输入中使用什么作为filename的默认值来工作?
即使是原始的SQL我会欣赏
首先,你缺少你的功能名称
function getFile($file_name = null){
$q = File::query();
if($file_name == null ){
// Do nothing this will get all files at the end since you haven't applied a where clause.
}else{
$q = File::where('filename',$file_name);
}
$result = $q->get();
return $result;
}