i need print task_id in file table when some user is going to attach files. this is My form.blade.php file action
files/form.blade.php
action="{{ route('projects.files', ['projectId'=> $project->id, 'taskId'=>$task->id])}}"> //and this is line 39
and this is FilesController
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();
}
and this is My file attachment routes
Route::post('projects/{projects}/files', [
'uses' => 'FilesController@uploadAttachments',
'as' => 'projects.files',
'middleware' => ['auth']
]);
and My file/form.blade.php is include with show.blade.php file in task folder in view directory
tasks/show.blade.php
{{$task->task_name}}
<hr>
{!!$task->body!!}
<hr>
@include('comments.form')
@include('files.form') // form.blade.php include
but unfortunately I got this following errors
ErrorException in ae0a86ab95cb7f092eb44a17fd000e94f21b305d.php line 39:
Undefined variable: task (View: C:\Users\13\Desktop\ddd\resources\views\files\form.blade.php)
how can fix this problem?
Edited this is My TaskController show methods
public function show($project_id,$task_id)
{
$project = Project::find($project_id);
$task = Task::find($task_id);
return view('tasks.show')->withProject($project)->withTask($task);
}
full form.blade.php codes
<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', $project->id, $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>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</div>
</div>