in my laravel 5.2アプリケーションファイル添付フォームがあり、ファイルテーブルに情報を保存します。タスクIDをLaravelのファイルテーブルに挿入する方法5.2
<form class="form-vertical" role="form"
enctype="multipart/form-data"
method="post"
action="{{ route('projects.files', ['projects' => $project->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>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
form.blade.php
ファイル/ Filecontroller
public function uploadAttachments(Request $request, $id,$taskId)
{
$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();
}
今、私は、ビュー、フォルダ、プロジェクト/ show.blade.phpのプロジェクトファイルにshow.blade.phpでタスクフォームを持っています
<form method="post" action="{{ route('projects.tasks.create', $project->id) }}">
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<input type="text" name="name" class="form-control" id="name" placeholder="Add Task" value="{{ old('name') ?: '' }}">
@if ($errors->has('name'))
<span class="help-block">{{ $errors->first('name') }}</span>
@endif
</div>
@endif
<br>
<div style='display:none'; class='somename'>
<div class="form-group">
<textarea name='body'class="form-control">{{ old('body') }}</textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Save</button>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
@include('files.form') //include File.form
は、これは私のファイルテーブル構造である
id file_name file_url project_id
私はタスクデータをフォームに入力すると私はファイル入力フォームも見ることができますが、今は各タスクに関連してファイルテーブルにtaskIdを入力する必要があります。これどうやってするの?
ここでは何も考えません – Lilan
この問題を解決するにはいくつかの助けが必要です – Lilan