无法在laravel中显示数据库表条目

时间:2018-01-09 03:37:29

标签: database laravel sqlite

我无法检索任何表数据,它只显示文本'没有即将发生的事件',就好像我的条目为0,但修补程序显示为否则。

任何人都可以在此查看任何错误或提供任何建议吗?它不久前工作,我不知道发生了什么,因为我的生活无法弄明白。我正在使用laravel和sqlite。

事件控制器:

use App\EventEntry;


class EventsController extends Controller
{
    public function displayEvent()

    {
        $entries = EventEntry::get();
        return view('eventdisplay', ['entries' => $entries]);

    }

EventEntry.php:

namespace App;

use Illuminate\Database\Eloquent\Model;

class EventEntry extends Model
{

}

路线:

Route::get('events', 'EventsController@displayEvent')->name('displayEvent');

events.blade.php:

<div>@include('eventdisplay')</div>

eventdisplay.blade.php:

<h1>Events</h1>

    @if($entries->count() == 0)
    <div>
    <p>There are no upcoming events.</p>
</div>
@else ...

迁移:

Schema::create('events', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->string('address');
    $table->string('description');
    $table->dateTime('event_date');
    $table->timestamps();
});

}

修补匠:

>>> DB::table('events')->get();
=> Illuminate\Support\Collection {#761
     all: [
       {#759
         +"id": "1",
         +"title": "Spring Festival",
         +"address": "demo",
         +"description": "lorem",
         +"event_date": "2018-02-23 09:00:00",
         +"created_at": null,
         +"updated_at": null,
       },
       {#758
         +"id": "2",
         +"title": "International Festival",
         +"address": "demo",
         +"description": "lorem",
         +"event_date": "2018-02-28 18:00:00",
         +"created_at": null,
         +"updated_at": null,
       },
     ],
   }

1 个答案:

答案 0 :(得分:1)

您需要为模型'事件'命名,或使用<select name="DateSelector" id="DateSelector" onchange="overviewDates();"> <option value="">Last 7 Days</option> <option value="">Last 14 Days</option> <option value="">Last 30 Days</option> <option value="">Last 90 Days</option> <option value="">Last 365 Days</option> </select> 属性覆盖表{1}}中的表名 -  表名部分:

  

请注意,我们没有告诉Eloquent我们的Flight模型使用哪个表。按照惯例,“蛇案例”,类的复数名称将用作表名,除非明确指定了其他名称。因此,在这种情况下,Eloquent将假设Flight模型将记录存储在航班表中。您可以通过在模型上定义表属性来指定自定义表: