无法在Laravel中显示表数据

时间:2017-07-15 07:09:33

标签: php mysql laravel-5

我需要在视图中显示一个任务表,列值" task_name"在show.blade.file @ tasks文件夹中,这是TaskController

 public function store(Request $request)//, $id, Task $task)
        {
            $task = new Task;
            $task->task_name= $request->input('name');
            $task->body = $request->input('body');
            $task->assign = $request->input('status');
            $task->priority = $request->input('status');
            $task->duedate = date("Y-m-d", strtotime($request->input("date")));// $request->input('date');
          //  $task->project_id = $id;
            $task->save();
        }

        public function show($id)
        {
            $task = Task::find($id);
            return view('tasks.show')->withTasks($task);
        }
 public function getTasks($id)
    {
        $tasks =  Task::find($id)->get();
        return $tasks;
    }

show.blade.php

 @if(isset($tasks))
     @foreach($tasks as $ta)
    <h1>{{ $ta->task_name }}</h1>
    @endforeach
    @endif

routes.php文件

Route::resource('tasks','TasksController');

否,任何错误但不在任务表中显示task_name

1 个答案:

答案 0 :(得分:0)

这样做

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" />
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>

    <div class="container">

        <div class="row">
            <div class="col-md-10">
                <label class="col-md-2">Search:</label>
                <div class="col-md-10">
                    <input type="text" class="form-control input-sm" id="txtSSN">
                </div>
            </div>
            <div class="col-md-2">
                <button class="btn btn-success btn-sm" id="btnSearch" type="submit"><i class="fa fa-search" aria-hidden="true"></i> SEARCH</button>
            </div>
        </div>

        <table class="table table-hover table-bordered" id="IPSCICODatatable">
            <thead>
                <tr>
                    <th>SSN or TIN</th>
                    <th>Customer ID</th>
                    <th>Account Number</th>
                    <th>Date Transaction</th>
                    <th>Trans Code</th>
                    <th>Trans Description</th>
                    <th>Amount</th>
                    <th>Cash in</th>
                    <th>Cash out</th>
                    <th>Source</th>
                </tr>
            </thead>
        </table>


    </div><!-- /.container -->


    <script src="https://code.jquery.com/jquery-1.12.4.min.js"
            integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
            crossorigin="anonymous"></script>

    <script src="~/Scripts/bootstrap.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var table = $('#IPSCICODatatable').DataTable({
                "ajax": {
                    "url": '/SOF45114671/GetAllCICO',
                    "type": "POST",
                    "datatype": "json",
                    "data": function (d) {
                        d.searchParameters = {};
                        d.searchParameters.ssn_or_tin = $('#txtSSN').val();
                        //...
                    }
                },
                "columns": [
                    { "data": "ssn_or_tin", "autoWidth": true },
                    { "data": "cusid", "autoWidth": true },
                    { "data": "accountNo", "autoWidth": true },
                    { "data": "dateTrans", "autoWidth": true },
                    { "data": "transCode", "autoWidth": true },
                    { "data": "transdescription_1", "autoWidth": true },
                    { "data": "amount", "autoWidth": true },
                    { "data": "cashin", "autoWidth": true },
                    { "data": "cashout", "autoWidth": true },
                    { "data": "source", "autoWidth": true }
                ]
            });

            $('#btnSearch').on("click", function (e) {
                alert("btnSearch_click");
                table.ajax.reload();

            });


        })

    </script>

</body>
</html>