调用未定义的方法 File::save()
Call to undefined method File::save()
我已经检查了所有有相同问题的线程,但仍然无法找出为什么不起作用。我有这个功能
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');
}
当我尝试将文件保存到数据库时出现以下错误。文件保存在目录中。
"Call to undefined method Illuminate\Support\Facades\File::save()"
- 将此
use Illuminate\Support\Facades\File;
替换为您的模型命名空间。
- 将此
$files= new \File();
替换为 $files= new File();
我已经检查了所有有相同问题的线程,但仍然无法找出为什么不起作用。我有这个功能
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');
}
当我尝试将文件保存到数据库时出现以下错误。文件保存在目录中。
"Call to undefined method Illuminate\Support\Facades\File::save()"
- 将此
use Illuminate\Support\Facades\File;
替换为您的模型命名空间。 - 将此
$files= new \File();
替换为$files= new File();