私のlaravelプロジェクト管理アプリケーション私はプロジェクトと1つのプロジェクトで多くのタスクを作成でき、1つのタスクはタスクに関して多くのファイルを公開しています。そう、私の添付ファイルの形でビューファイル内のファイルフォルダでこれをある(file.form)blade.phpファイルをlaravelに別のブレードファイルと一緒に入れる方法
ファイル/ form.blade.php
@foreach ($task->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', ['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>
とタスクモデルとファイルモデルの関係は、この
public function task(){
return $this->belongsTo(Task::class);
}
タスクでありますファイルモデルとのモデル関係はこれです
public function files(){
return $this->hasMany('App\File');
}
今、私はファイル/ form.blade.php私は、タスクを表示しようとすると、
<h2>{{ $task->project->project_name }}</h2>
<hr>
{{$task->task_name}}
<hr>
{!!$task->body!!}
<hr>
@include('files.form')
この
タスク/ show.blade.phpなどのタスク/ show.blade.phpファイルとファイル/
を来ているこの次のエラーを提出show.blade.phpUndefined variable: task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php)
どのようにこの問題を解決できますか?
この問題を解決するための考えはありません – John
私はここにいくつかの助けが必要です – John
これ以上の詳細は必要ですか? – John