我已经检查了所有具有相同问题的线程,但仍然找不到为什么不起作用。我有这个功能
namespace App\Http\Controllers\Admin;
use App\MediaKit;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Validator ;
use Illuminate\Support\Facades\File;
class MediaKitController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'filename' => 'required',
'filename.*' => 'mimes:doc,pdf,docx,zip,png'
]);
if($request->hasfile('filename'))
{
foreach($request->file('filename') as $files)
{
$name = $files->getClientOriginalName();
$files->move(public_path().'/files/', $name);
$data[] = $name;
}
}
$files= new \File();
$files->filename=json_encode($data);
$files->save();
return back()->with('success', 'Your files has been successfully added');
}
当我尝试将文件保存到数据库时,出现以下错误。这些文件将保存在目录中。
“调用未定义的方法Illuminate \ Support \ Facades \ File :: save()”
答案 0 :(得分:1)
use Illuminate\Support\Facades\File;
替换为模型名称空间。$files= new \File();
替换为$files= new File();