所以我在表单中有一个隐藏的输入,我在其中设置了旧文件的名称
public function update(Request $request, $id)
{
$company = Company::find($id);
$company->name = $request->input('name');
$company->address = $request->input('address');
// $company->logo = $request->input('logo');
if(null !== (($request->file('logo')))) {
File::delete('logo/' . $request->input('old_logo'));
$request->file('logo')->store('logo');
$company->logo = $request->file('logo')->hashName();
}
$company->save();
return redirect('admin/companies');
}
它已成功设置:
storage/app/public/logo/
>
然后它转到我的控制器:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/public'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
我要删除的文件存储在storage/app/public/logo/
Filesystems.php
$request->input('old_logo')
它应该尝试从use File;
删除?正如我测试class Person
has_many :accounts
has_many :computers, through: :accounts
end
class Account
belongs_to :person
belongs_to :computer
scope :administrators, -> { where(role: 'administrator') }
end
class Computer
has_many :accounts
has_many :people, through: :accounts
end
也成功通过。我做错了什么?这可能是权利问题吗?
当然我写了这个:person.accounts.administrators.map(&:computer)
答案 0 :(得分:2)
您需要传递文件的完整路径。因此,如果文件位于public/logo
目录中,请执行以下操作:
File::delete(public_path('logo/' . $request->old_logo));