hi, in my laravel 5.2 application I have file attachment form and save information in file table.
files/form.blade.php
<form class="form-vertical" role="form"
enctype="multipart/form-data"
method="post"
action="">
<div class="form-group">
<input type="file" name="file_name" class="form-control" id="file_name">
@if ($errors->has('file_name'))
<span class="help-block"></span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Add Files</button>
</div>
<input type="hidden" name="_token" value="">
</form>
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();
}
now I have task form in show.blade.php in projects file in view folder projects/show.blade.php
<form method="post" action="">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Add Task" value="">
@if ($errors->has('name'))
<span class="help-block"></span>
@endif
</div>
@endif
<br>
<div style='display:none'; class='somename'>
<div class="form-group">
<textarea name='body'class="form-control"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Save</button>
</div>
<input type="hidden" name="_token" value="">
</form>
@include('files.form') //include File.form
this is my file table structure
id file_name file_url project_id
now when I open task data enter form I can see file enter form also, but now I need enter taskId to the file table with related to the each tasks. how can do this?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ybecQQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire