如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”)

时间:2016-06-22 08:36:46

标签: laravel

如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”)  我是新的并使用laravel框架。 这是我的观点

                    <table class="table table-striped" id="example">

                        <thead>
                        <tr>
                            <th>ID no</th>
                            <th>Form Name</th>
                            <th style="text-align: center">Update</th>
                            <th>Delete</th>
                            <th>Status</th>
                        </tr>
                        </thead>
                        @foreach($form as $show)

                            {{--modal--}}
                        <div class="modal fade mj_popupdesign mj_checkoutpopup" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-body">
                                        <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-2">
                                            <div class="row">
                                                <div class="mj_pricingtable mj_greentable mj_login_form_wrapper">
                                                    <form>
                                                        <div class="mj_login_form">

                                                            <p>Are you sure you want to delete this post?</p>
                                                            <br>
                                                            <a href="" class="mj_btn btn btn-default pull-right glyphicon glyphicon-remove "> No</a>

                                                            <a href="{{url('deleteForm',$show->id)}}" class=" pull-right mj_btn btn btn-danger  glyphicon glyphicon-ok"> Yes</a>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                        {{--end modal--}}
                            <tbody>
                        <tr>
                            <td>
                                <p>
                                    {{$show->id}}</p>
                            </td>
                            <td>
                                <h6><a href="{{url('JobDetails',$show->id)}}"style="color: rgb(0, 191, 243);font-size:18px;float: left;margin: 0;text-align: left">{{$show->jobTitle}}</a> </h6>
                                <p>
                                    {{$show->created_at}} </p>
                            </td>
                            <td>
                                <a href="{{url('UpdateFormView',$show->id)}}"> <span class="mj_btn btn btn-success">Update</span>
                                </a>
                            </td>
                            <td>
                                <span class="mj_btn btn btn-danger"  data-toggle="modal" data-target="#myModal2">Delete</span>
                            </td>
                            <td><span class="mj_btn btn btn-warning">pending</span>
                            </td>
                        </tr>
                            </tbody>
                        @endforeach
                    </table>

                </div>

            </div>
        </div>
    </div>

并在我的控制器中

public function AcquiredForm()
{
    $acquired="Requirement Form";
    $acquireForm=Job::where('jobType','LIKE','%'.$acquired.'%');
    $form = $acquireForm->get();
    return view('private-pages.company.aquire-form',compact('form'));

}
数据库状态中的

默认为待处理

enter image description here

2 个答案:

答案 0 :(得分:1)

  数据库状态中的

默认为待处理

我的代码上没有status属性,但是显示状态待定的纯字符串

<span class="mj_btn btn btn-warning">pending</span>
<!-- while it suppose to be -->
<span class="mj_btn btn btn-warning">{{ $show->status }}</span>

假设它确实存在,你可以

<td>
@if ($show->status === 'Accept')
    <span class="mj_btn btn btn-green">Accepted</span>
@elseif ($show->status === 'Delete')
    <span class="mj_btn btn btn-danger">Deleted</span>
@else
    <span class="mj_btn btn btn-warning">Pending</span>
@endif
</td>

请参阅:https://laravel.com/docs/5.1/blade#displaying-data

答案 1 :(得分:0)

    <td>
                                @if ($show->jobstatus === "Accepted")
                                    <span class="mj_btn btn btn-success">Accepted</span>
                                @elseif ($show->jobstatus === "Rejected")
                                    <span class="mj_btn btn btn-danger">Rejected</span>
                                @else
                                    <span class="mj_btn btn btn-warning">Pending</span>
                                @endif
                            </td>