我有一个Laravel设置,我可以在其中添加文件并将其删除。现在,当我尝试删除服务器上的网站上的图标时,我得到了
Not Found
The requested URL /icons/24 was not found on this server.
上传文件并检索文件有效。当我在本地测试时,它可以工作。而且我的工作方式与图像,视频文件和音频文件完全相同,而且这些都可以在服务器上运行。
为了调试它我还在控制器中添加了show()
函数,并且该函数也给出了同样的问题。发生了什么事?
routes / web.php :(部分)
Route::get('iconFile/{id}','IconController@iconFile');
Route::get('imageFile/{id}','ImageController@imageFile');
Route::get('audioFile/{id}','AudioController@audioFile');
Route::get('videoFile/{id}','VideoController@videoFile');
Route::get('signlanguageFile/{id}','SignlanguageController@signlanguageFile');
Route::group(['middleware' => ['auth']], function() {
Route::post('image-upload-with-validation',['as'=>'postimage','uses'=>'ImageController@postImage']);
Route::post('icon-upload-with-validation',['as'=>'posticon','uses'=>'IconController@postIcon']);
Route::resource('texts', 'TextController');
Route::resource('icons', 'IconController');
Route::resource('images', 'ImageController');
Route::resource('videos', 'VideoController');
Route::resource('signlanguages', 'SignlanguageController');
Route::resource('audios', 'AudioController');
});
IconController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Icon;
use Storage;
class IconController extends Controller
{
public function iconFile($id)
{
$icon = Icon::find($id);
$contents = Storage::disk('local')->get('uploads/icons/'.$icon->file);
$response = Response($contents);
$response->header('Content-Type', 'icon');
return $response;
}
public function show($id)
{
$icon = Icon::find($id);
$data = [
'icon' => $icon
];
echo $icon;
//return view('icon', $data);
}
public function postIcon(Request $request)
{
$this->validate($request, [
'icon_file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:10000',
]);
$iconName = time().'.'.$request->icon_file->getClientOriginalExtension();
$request->icon_file->move(storage_path('app/uploads/icons'), $iconName);
$icon = new Icon;
$icon->parent_id = $request->parent_id;
$icon->file = $iconName;
$icon->save();
return back()
->with('success','You have successfully uploaded an icon.')
->with('icon',$iconName);
}
public function destroy($id)
{
$icon = Icon::find($id);
$section_id = $icon->parent_id;
Storage::delete('uploads/icons/'.$icon->file);
$icon->delete();
return redirect('/section/'.$section_id)->with('success','Icon deleted.');
}
}
更新
我尝试将资源路由替换为Route::resource('iconz', 'IconController');
(使用z),然后就可以了!将其更改回&#34;图标&#34;让它再次停止工作。图标可以是某种保留字吗?
还尝试php artisan route:clear
没有帮助。