如何在Laravel中将模型变量添加到另一个模型

时间:2016-12-01 12:09:08

标签: php laravel-5

我的问题是我在视图中有$collaborator(模型)变量。在视图中,有与$permission模型相关的表单。现在我需要将$permission添加到我的视图文件中。我怎么能这样做我的刀片视图是这样的  我需要此刀片文件上的权限表的打印状态值。我需要在这里获得$permission

我的刀片文件是

 @if($collaborators) // I need add $permission here
           @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,$collaborator->id) }}">
                        <!--<div id="cid" name="cid">{{ $collaborator->user()->first()->id}}</div>-->
                    <input type="hidden" 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()

0 个答案:

没有答案