简体   繁体   English

Laravel视图没有显示任何东西,它显示为空白

[英]Laravel view doesn't show anything it'show blank

I have a view in the project but it doesn't show anything, I want to show data in the table but the page is blank.it was working yesterday but its just a blank page,don't know what happened, please help.. 我在项目中有一个视图,但没有显示任何内容,我想在表中显示数据,但是页面为空白。它昨天工作了,但它只是一个空白页面,不知道发生了什么,请帮助。 。

1.is it problem of route 2.database issue 3.html error 1.路由问题2.数据库问题3.html错误

route 路线

   <?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 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 @endsection

my controller function 我的控制器功能

<?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)
    {
        //
    }
}

You have overlapping route definitions: 您有重叠的路线定义:

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

The latter is being used. 正在使用后者。

Probably change the latter to something like: 可能将后者更改为:

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

If it doesn't show anything Laravel's error reporting features are probably turned off. 如果未显示任何信息,Laravel的错误报告功能可能已关闭。 Because almost always it says what's wrong. 因为几乎总是说出了什么问题。 Maybe you should look in to that first. 也许您应该先考虑一下。

Problem with your route.Because once you use resource and then use declare the route as a get, First you clear what route you are using. 路由问题。因为一旦使用资源 ,然后使用声明该路由为get,首先要清除正在使用的路由。

Here below is the when resource using , example below. 以下是使用的when 资源 ,下面的示例。

http://www.expertphp.in/article/laravel-5-5-crud-create-read-update-delete-example-from-scratch http://www.expertphp.in/article/laravel-5-5-crud-create-read-update-delete-example-from-scratch

Remove these lines as you have already declared resource routing: 因为已经声明了resource路由,所以Remove这些行:

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

Your route are replaced by the second route thats why its show empty page because your create() dosn't do anything ie empty page. 您的路线被第二条路线所取代,这就是为什么它显示空白页的原因,因为您的create()没有执行任何操作,即空白页。

I would suggest you to rename create route as below Try below code : 我建议您重命名创建路线,如下所示尝试以下代码:

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

Try to delete the cache stored in the storage -> framework -> cache folder 尝试删除存储在storage -> framework -> cache folder

if still fails, Try to call composer dump-autoload via your cmd to reload your soure code. 如果仍然失败,请尝试通过cmd调用composer dump-autoload以重新加载源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM