I am developing project management tool in laravel 5.2. In my application user can create a project and one project has many tasks and one task may have many files attachments. I am using cloudder to save My files. Currently I have assigned My project files to relevant projects only. Now, I need to display the files on each tasks of the relevant projects.
FileController
class FilesController extends Controller
{
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();
}
return redirect()->route('projects.show')->with('info', 'File deleted successfully');
}
}
routes
Route::post('projects/{projects}/tasks/{tasks}/files', [
'uses' => 'FilesController@uploadAttachments',
'as' => 'projects.files',
'middleware' => ['auth']
]);
and file form is 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="" target="_blank"></a>
</span>
</div>
</div>
<hr/>
@endforeach
<form class="form-vertical" role="form"
enctype="multipart/form-data"
method="post"
action="">//this is line 39
<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>
now I got this error
ErrorException in 88ff5154a46f749c29024e0c9f84c577f7c5025e.php line 39: Undefined variable: task (View: C:\Users\Lilan\Desktop\acxian\resources\views\files\form.blade.php)
how to fix this problem?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hlNB8w
via IFTTT
Aucun commentaire:
Enregistrer un commentaire