2016-11-19 4 views
2

私はイベントビューを持っています。ユーザーはイベントを作成でき、すべてのイベントはイベントページで見ることができます。何らかの理由で、私のTime列を除いてすべてのデータがテーブルに表示されます。Laravel私の時間以外のすべてを表示

私はここにいくつかのコードがありますが、テーブルビューで空になっている理由についての手掛かりがあります。

イベントコントローラ

public function event() 
 
{ 
 
    $events = Event::all(); 
 
    return view('pages.event', compact('events')); 
 
} 
 

 
public function createEvent() 
 
{ 
 
    return view('pages.createevent'); 
 
} 
 

 
public function newEvent() 
 
{ 
 
    $event = Event::create(Request::only(
 
    'name', 
 
    'description', 
 
    'location', 
 
    'time', 
 
    'start_date', 
 
    'end_date' 
 
    )); 
 

 
    $event->save(); 
 

 
    \Session::flash('flash_message', 'Event Created Successfully!'); 
 

 
    return redirect('event'); 
 
}
イベントの時間が挿入されている

<table class=" display table table-hover table-bordered" , id="event"> 
 
    <thead> 
 
    <th>Name</th> 
 
    <th>Description</th> 
 
    <th>Location</th> 
 
    <th>Time</th> 
 
    <th>Start Date</th> 
 
    <th>End Date</th> 
 
    <th>Functions</th> 
 

 
    </thead> 
 
    <tbody> 
 
    @foreach($events as $event) 
 
    <tr> 
 
     <td>{{ $event->name }}</td> 
 
     <td>{{ $event->description }}</td> 
 
     <td>{{ $event->location }}</td> 
 
     <td>{{ $event->time }}</td> 
 
     <td>{{ $event->start_date }}</td> 
 
     <td>{{ $event->end_date }}</td> 
 
     <td> 
 
     <button type="button" class="btn btn-default" style="float:left; margin-right:5px;"><a href="pages/editevents/{{$event['id']}}"><i class="fa fa-pencil" aria-hidden="true"></i> 
 
             Edit</a> 
 
     </button> 
 
     <button type="button" class="btn btn-default" style="display:inline; margin-right:auto;"><a href="deleteEvent/{{$event['id']}}">Delete</a> 
 
     </button> 
 
     </td> 
 
    </tr> 
 
    @endforeach 
 
    </tbody> 
 
</table>

を見ます私のデータベースには問題ありませんが、私の見解では表示されません。

データ型DBで

Data Types

Table in Database

イベントが Events View

を見ます3210

私のtimeデータタイプと関係がありますか?これについての助けがあれば、大歓迎です!それはあなたの列が定義されている方法ですので、あなたは、大文字で$event->Timeを使用する必要があります

イベントモデル

namespace App\Models; 
 
use Illuminate\Database\Eloquent\Model; 
 
/** 
 
* Class Events 
 
*/ 
 
class Event extends Model 
 
{ 
 
    protected $table = 'Events'; 
 
    protected $primaryKey = 'id'; 
 
    public $timestamps = false; 
 
    protected $fillable = [ 
 
     'name', 
 
     'description', 
 
     'location', 
 
     'time', 
 
     'start_date', 
 
     'end_date' 
 
    ]; 
 
    protected $guarded = []; 
 
}

+0

は一貫性があり、小文字を使用します。時間はありませんが、時間は(データベース内で)です。 – Kyslik

+0

@Kyslikデータベースを小文字に変更しました。ありがとうございます。それは今見せている。あなたは24時間ではなく12時間AM/PMにフォーマットする方法を知っていますか?再度、感謝します! –

+0

今後google、http://ideone.com/NkvsjN – Kyslik

答えて

1

。モデルプロパティは大文字と小文字を区別します

+0

ありがとうございました。私はMySqlWorkbenchでテーブルを作成し、Laravelでモデルを作成しました。テーブルの私のデータ型は 'time'型ですが、datetimeに切り替えて、' $ event-> time-> toDateTimeString() 'を使用してください。私の 'start_dateとend_date'はうまく表示されます。 –

+0

あなたのコントローラで 'dd($ event-> time);'を試して、このプロパティのタイプを確認してください。 –

+0

'未定義のプロパティ:Illuminate \ Database \ Eloquent \ Collection :: $ time'というエラーメッセージが表示されます –

関連する問題