gpt4 book ai didi

php - 如何修复 App\Http\Controllers\FilesController::uploadAttachments() 缺少参数 3

转载 作者:行者123 更新时间:2023-11-29 18:13:01 28 4
gpt4 key购买 nike

我正在 Laravel 5.2 中开发项目管理工具。在我的应用程序中,用户可以创建一个项目,一个项目有许多任务,一个任务可能有许多文件附件。我正在使用 cloudder 来保存我的文件。目前我已将我的项目文件仅分配给相关项目。现在,我需要显示相关项目的每个任务的文件。

文件 Controller

class FilesController extends Controller
{

public function uploadAttachments(Request $request, $id,$taskId) //this is line 20
{
$this->validate($request, [
'file_name' => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
]);

$filename = $request->file('file_name')->getRealPath();

Cloudder::upload($filename, null);
list($width, $height) = getimagesize($filename);

$fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
$this->saveUploads($request, $fileUrl, $id,$taskId);

return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
}

private function saveUploads(Request $request, $fileUrl, $id,$taskId)
{
$file = new File;
$file->file_name = $request->file('file_name')->getClientOriginalName();
$file->file_url = $fileUrl;
$file->project_id = $id;
$file->task_id = $taskId;

$file->save();
}

return redirect()->route('projects.show')->with('info', 'File deleted successfully');
}
}

路线

Route::post('projects/{projects}/files', [
'uses' => 'FilesController@uploadAttachments',
'as' => 'projects.files',
'middleware' => ['auth']
]);

文件格式为files/form.blade.php

 <div class="row" style="border:1px solid #ccc;margin-left:5px;width:100%;padding:15px;">
@foreach($project->files as $file)
<div>
<div><i class="fa fa-check-square-o"></i>
<span>

<a href="{{ $file->file_url }}" target="_blank">{{ $file->file_name }}</a>
</span>
</div>
</div>
<hr/>
@endforeach

<form class="form-vertical" role="form"
enctype="multipart/form-data"
method="post"
action="{{ route('projects.files', ['projectId'=> $project->id, 'taskId'=>$task->id])}}">
<div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
<input type="file" name="file_name" class="form-control" id="file_name">
@if ($errors->has('file_name'))
<span class="help-block">{{ $errors->first('file_name') }}</span>
@endif
</div>

<div class="form-group">
<button type="submit" class="btn btn-info">Add Files</button>
</div>

现在我得到了这个错误:

ErrorException in FilesController.php line 20: Missing argument 3 for App\Http\Controllers\FilesController::uploadAttachments()

我该如何解决这个问题?

最佳答案

您没有在路由声明中传递所需的参数。
添加 projectIdtaskId

Route::post('projects/{projectId}/files/{taskId}', [
'uses' => 'FilesController@uploadAttachments',
'as' => 'projects.files',
'middleware' => ['auth']
]);

并在 Controller 方法中正确提及它们。

public function uploadAttachments(Request $request, $projectId, $taskId)
{
//
}

关于php - 如何修复 App\Http\Controllers\FilesController::uploadAttachments() 缺少参数 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47245797/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com