Php 如何解决laravel中不存在的文件问题
我使用observer类存储图像,一切正常,例如图像存储在公用文件夹中,保存在数据库中,但保存后会出现如下错误 我在我的学生观察课上试过这个Php 如何解决laravel中不存在的文件问题,php,laravel,Php,Laravel,我使用observer类存储图像,一切正常,例如图像存储在公用文件夹中,保存在数据库中,但保存后会出现如下错误 我在我的学生观察课上试过这个 protected $request; public function __construct(Register $request) { $this->request = $request; } public function created(Student $student) {
protected $request;
public function __construct(Register $request)
{
$this->request = $request;
}
public function created(Student $student)
{
//
}
public function creating(Student $student)
{
//dd($request->image);
if ($this->request->hasFile('image')) {
$file = $this->request->image;
$destinationPath = public_path().'/images/';
$filename= $student->username . '.'.$file->clientExtension();
$file->move($destinationPath, $filename);
$student->image=$filename;
}
}
在我的控制器里
public function create(Register $request)
{
$student=new Student;
$student->name = $request->input('name');
$student->username = $request->input('username');
$student->email = $request->input('email');
$student->password = bcrypt($request->input('password'));
$student->gender = $request->input('gender');
$student->phone = $request->input('phone');
$student->save();
$student->subjects()->attach($request->id);
return home('home');
}
您是否检查了正在移动和保存的图像是否正确?是否可能重复?是的,这是我的问题,但当时图像根本没有保存,这次一切正常,但最后出现了错误。因此,您的第一个问题没有正确回答,对吗?去检查一下这个问题的答案,你会发现你的问题的解决方案。实际上,当时我在控制器中使用了全部代码,其中一个答案是正确的。但现在我想在observer类上使用它