2016-08-12 6 views
1

プロジェクトフォルダ内のindex.blade.phpを含むcollaboratorフォルダ内に、form.blade.phpファイルを@includeにする必要があります。ブレードファイルをLaravelの別のブレードファイルに組み込む方法

これはこれは私のform.blade.phpファイル

<div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;"> 
    <h4 class="page-header"> 
     Collaborators 
    </h4> 
    @if($collaborators) 
     @foreach($collaborators as $collaborator) 
      <div> 
       <div> 
        <span> 
         <img src="{{ $collaborator->user()->first()->getAvatarUrl() }}" /> 
         {{ $collaborator->user()->first()->username}} 
         {{ $collaborator->user()->first()->id}} 

        </span> 
       </div> 
       <button class="btn btn-sm btn-danger delete" style="margin-top:5px;padding:4px;width:35px;" 
        data-action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->collaborator_id }}" 
        data-token="{{csrf_token()}}"> 
       <i class="fa fa-trash-o"></i> 
       </button> 

       <!-- permission start --> 

       <form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.permission', $project->id) }}"> 
        <!--<div id="cid" name="cid">{{ $collaborator->user()->first()->id}}</div>--> 
       <input type="number" id="cid" name="cid" value="{{ $collaborator->user()->first()->id }}" /> 
       <div class="form-group{{ $errors->has('status') ? ' has-error' : '' }}"> 
       <label for="status" class="control-label">Choose Permission</label> 
       <select name="status" id="status"> 
       <option value="">Choose a status</option> 
       <option value="3">View Only</option> 
       <option value="2">Edit Tasks</option> 
       <option value="1">Admin</option> 
       </select> 
       @if ($errors->has('status')) 
       <span class="help-block">{{ $errors->first('status') }}</span> 
       @endif 
       </div> 
        <div class="form-group"> 
        <button type="submit" class="btn btn-default">Create</button> 
        </div> 
        <input type="hidden" name="_token" value="{{ csrf_token() }}"> 


       </form> 

       <!-- permission end --> 


      </div> 
      <hr/> 
     @endforeach 
    @endif 
    <form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.create', $project->id) }}"> 
    <div class="form-group{{ $errors->has('collaborator') ? ' has-error' : '' }}"> 
     <label> Add New </label> 
     {!! mention()->asText('collaborator', old('collaborator'), 'users', 'username', 'form-control') !!} 
     @if ($errors->has('collaborator')) 
      <span class="help-block">{{ $errors->first('collaborator') }}</span> 
     @endif 
    </div> 

    <div class="form-group"> 
     <button type="submit" class="btn btn-info">Add User</button> 
    </div> 
    <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
    </form> 

が、インクルードファイルの後に次の生成であるindex.blade.phpファイル

@extends('layouts.app') 
@section('content') 

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> 
@include('layouts.partials.alerts') 
<h1 class="page-header">Projects<a class="btn btn-info" href="{{ route('projects.create') }}">New Project</a></h1> 

<div class="container"> 
    @if($project) 

    <div class="row"> 
     @foreach ($project as $proj) 
      <div class="col-md-3" style="border:1px solid #ccc;margin-left:5px;"> 
      <h2><a href="/projects/{{ $proj->id }}">{!! $proj->project_name !!}</a></h2> 
      <p>Due : {!! date_format(new DateTime($proj->due_date), "D, m Y") !!}</p> 
      <p>Status: {!! $proj->project_status !!}</p> 
      <p>Tasks: 0</p> 
      <p>Comments: 0</p> 
      <p>Attachments: 0</p> 
      </div> 

     @endforeach 
    </div> 
    @endif 

    <div> 
    @include('collaborators.form')<!-- This is include file --> 
    </div> 

    @if($project->isEmpty()) 
    <h3>There are currently no Projects</h3> 
    @endif 
</div> 





<div class="container"> 
    <a class="btn btn-info" href="{{ route('projects.create') }}">New Project</a> 

</div> 

ですエラー

Undefined variable: collaborators (View: C:\Users\Fernmax\Desktop\c\resources\views\collaborators\form.blade.php) 

私はこれを解決する解決策を教えてくれますか?

ありがとうございました!ビューへ

+0

あなたのコントローラでは、あなたは 'ret ( 'collaborator'、$ collaborator); ' – feareoc

+0

はい、しかし次のエラーメッセージが表示されます。' '未定義変数:協力者' ' – Fernando

+0

'{{isset($ collaborator)? 'true': 'false'}} 'あなたのインデックスビューとあなたのcollaborator.formビューでは、あなたのインデックスビューで設定されていない場合は、 – feareoc

答えて

0

パスcollaborators

return view('index')->with('collaborators', $collaborator); 

そして、あなたの$collaborators変数必要があります:あなたは同じように、$collaborators変数を設定した後

@include('collaborators.form', ['collaborators' => $yourData]) 
0

があなたのコントローラまたはルートコールバックからあなたのビューに$collaboratorsを渡します自動的に付属のcollaborators.formビューに渡されます

関連する問題