Laravel视图没有显示任何显示空白的内容

时间:2018-03-19 06:46:24

标签: php laravel laravel-5.6

我在项目中有一个视图,但它没有显示任何内容,我想在表格中显示数据,但页面是空白的。昨天正在工作,但它只是一个空白页面,不要知道发生了什么事,请帮忙..

1.路线问题 2.数据库问题 3.html错误

路线

   <?php


Route::get('/', function () {
    return view('welcome');
});


Route::resource('books','BookController');
Route::resource('news','NewsController');
//Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
Route::get('my-home', 'HomeController@myHome');

Route::get('my-users', 'HomeController@myUsers');

Route::get('/news','NewsController@index');
Route::get('/news','NewsController@create');

Index.blade.php

  @extends('theme.default')

@section('content')

    <div class="row">

        <div class="col-lg-12">

            <h1 class="page-header">ADVERTISEMENT DETAILS</h1>

        </div>

        <!-- /.col-lg-12 -->

    </div>

    <!-- /.row -->

    <div class="row">

        <div class="col-lg-3 col-md-6">

            <div class="panel panel-primary">

                <div class="panel-heading">

                    <div class="row">

                        <a href="#">

                            <div class="panel-footer">

                                <span class="pull-left">Create New News</span>

                                <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>

                                <div class="clearfix"></div>

                            </div>

                        </a>

                    </div>

                </div>


            </div>

        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Added News
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="table-responsive">
                                    <table class="table table-striped table-bordered table-hover"
                                           id="dataTables-example">
                                        <thead>
                                        <tr>
                                            <th>Slno</th>
                                            <th>News Name</th>
                                            <th>News Details</th>
                                            <th>News Link</th>
                                            <th>News Status</th>
                                            <th>EDIT</th>
                                            <th>DELETE</th>
                                        </tr>
                                        </thead>
                                        <?php $i = 1; ?>
                                        <tbody>

                                        @foreach($news as $news)

                                            <tr>

                                                <td>{{ $news->$id }}</td>
                                                <td>{{ $news->name }}</td>
                                                <td>{{ $news->news }}</td>
                                                <td>{{ $news->alink }}</td>
                                                @if($news->status==0)
                                                    <td>ACTIVE</td>
                                                @else
                                                    <td>INACTIVE</td>
                                                @endif
                                                <td><a href="{{route('news.edit',$news->id)}}"><input type="button"
                                                                                                      name="edit"
                                                                                                      value="EDIT"> </a>
                                                <td><input type="button" name="delete" value="DELETE"></td>
                                            </tr>

                                        @endforeach
                                        </tbody>


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

        <!-- /. PAGE INNER  -->
    </div>

@endsection

我的控制器功能

<?php

namespace App\Http\Controllers;

use App\News;
use Illuminate\Http\Request;

class NewsController extends Controller
{

    public function index()
    {
        $news=News::all();
        return view('news.index',['news'=>$news]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
//        return view('news.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\News  $news
     * @return \Illuminate\Http\Response
     */
    public function show(News $news)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\News  $news
     * @return \Illuminate\Http\Response
     */
    public function edit(News $news)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\News  $news
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, News $news)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\News  $news
     * @return \Illuminate\Http\Response
     */
    public function destroy(News $news)
    {
        //
    }
}

6 个答案:

答案 0 :(得分:2)

您有重叠的路线定义:

Route::get('/news','NewsController@index');
Route::get('/news','NewsController@create');

正在使用后者。

可能会将后者改为:

Route::get('/news/create', 'NewsController@create');

答案 1 :(得分:0)

如果它没有显示任何内容,可能会关闭Laravel的错误报告功能。因为它几乎总是说出了什么错。也许你应该首先考虑一下。

答案 2 :(得分:0)

您的路线出现问题。因为一旦您使用资源然后使用声明路线作为获取,首先您要清除您正在使用的路线。

以下是使用资源时的示例。

https://github.com/angular/material2/tree/master/src/material-examples/table-filtering

答案 3 :(得分:0)

Remove这些行已经声明resource路由:

Route::get('/news','NewsController@index');
Route::get('/news','NewsController@create');

答案 4 :(得分:0)

您的路线被第二条路线取代,这就是为什么它显示空白页面,因为您的create()不会做任何事情,即空页。

我建议你重命名创建路线,如下所示 请尝试以下代码:

Route::get('/news','NewsController@index');
Route::get('/news/create','NewsController@create');

答案 5 :(得分:0)

尝试删除存储在storage -> framework -> cache folder

中的缓存

如果仍然失败,请尝试通过您的cmd致电composer dump-autoload重新加载您的源代码。