2017-10-29 12 views
0

私のlaravelプロジェクト管理アプリケーションの未定義変数:タスク(表示:C:¥Users¥Lilan¥Desktop¥ddd¥resources¥views¥files¥form.blade.php)を修正します。多くのタスクを作成することができ、1つのタスクはタスクに関する多くのファイルを公開します。そう、私の添付ファイルの形でビューファイル内のファイルフォルダでこれをある未定義変数の修正方法: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.php
Undefined variable: task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) 

どのようにこの問題を解決できますか?

編集した質問

public function uploadAttachments(Request $request, $id) 
    { 
     $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); 

     return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully'); 
    } 

    private function saveUploads(Request $request, $fileUrl, $id) 
    { 
     $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(); 
    } 

新これが私のコメントフォームであり、これはここでうまく

コメント/ form.blade.php

@foreach ($task->project->comments as $comment) 

    <div> 
        <div><i class="fa fa-check-square-o"></i> 
        <span>{{ $comment->comments }} by 
         <span style="font-style: italic;color: #09f;"> 
         {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
         </span> 
        </span></div> 
        <a href="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}/edit">Edit</a> 
        <button class="btn btn-danger delete pull-right" 
         data-action="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}" 
         data-token="{{csrf_token()}}"> 
        <i class="fa fa-trash-o"></i>Delete 
        </button> 
       </div> 
       <hr/> 

@endforeach 
を働いている質問

を編集しました

と私はあなたのコードが、簡単なlaravel作品について確認していないタスク/ show.blade.php

@include('comments.form') 
@include ('files.form') 

私のコメントフォームが動作しているが、ファイル形式が動作していない....

+0

に何ら本件 – Lilan

+0

についての考え方は、いくつかの助けを必要としない... – Lilan

+0

あなたのコントローラが 'ビュー()'メソッドに戻っているものを私の編集した質問 – Lilan

答えて

0

に含めますこのよう

// routes/web.php 
Route::get('app.tasks', [email protected]); 

// Model [App] 
class App { 
    public $fillable = ['name']; 

    public function task(){ 
     return $this->belongsTo(Task::class); 
    } 
} 

// Controller 
class TaskController { 
    public function index() { 
     $app = App::get(); 
     return view('home.app', ['app' => $app]); // resources/view/home/app.blade.php 
    } 
} 

// resources/view/home/app.blade.php 

<div>{{ $app->name }}</div> 
<div>{{ $app->task()->id }}</div> 
+0

私の新しい編集の質問 – Lilan

+0

はここにありません.... – Lilan

関連する問題