Permalink
Browse files

✨ Viewing our events

  • Loading branch information...
lorisleiva committed Aug 17, 2018
1 parent 7cac0f3 commit 9989439a256afb5a32d09fdd6dfc5cbeee95c465
Showing with 82 additions and 0 deletions.
  1. +18 βˆ’0 app/Http/Controllers/EventController.php
  2. +13 βˆ’0 app/User.php
  3. +46 βˆ’0 resources/views/events.blade.php
  4. +1 βˆ’0 resources/views/layouts/app.blade.php
  5. +1 βˆ’0 resources/views/welcome.blade.php
  6. +3 βˆ’0 routes/web.php
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
use App\Event;
use Illuminate\Http\Request;
class EventController extends Controller
{
public function index()
{
$events = auth()->user()->events()
->orderBy('started_at', 'desc')
->get();
return view('events', compact('events'));
}
}
View
@@ -2,6 +2,7 @@
namespace App;
use App\Event;
use App\GoogleAccount;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -22,4 +23,16 @@ public function googleAccounts()
{
return $this->hasMany(GoogleAccount::class);
}
public function events()
{
// Or use: https://github.com/staudenmeir/eloquent-has-many-deep
return Event::whereHas('calendar', function ($calendarQuery) {
$calendarQuery->whereHas('googleAccount', function ($accountQuery) {
$accountQuery->whereHas('user', function ($userQuery) {
$userQuery->where('id', $this->id);
});
});
});
}
}
@@ -0,0 +1,46 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
Events
</div>
<div class="card-body">
<ul class="list-group list-group-flush">
@forelse ($events as $event)
<li class="list-group-item d-flex justify-content-between align-items-center">
<div>
<strong>{{ $event->name }}</strong><br>
<span class="text-muted">
@if ($event->allday)
{{ $event->started_at->format('l jS F Y') }}
(all day)
@else
{{ $event->started_at->format('l jS F Y \a\t H:i') }}
({{ $event->duration }})
@endif
</span>
</div>
<span
class="badge badge-pill"
style="background-color: {{ $event->calendar->color }};"
>
{{ $event->calendar->name }}
</span>
</li>
@empty
<li class="list-group-item">
No events.
</li>
@endforelse
</ul>
</div>
</div>
</div>
</div>
</div>
@endsection
@@ -35,6 +35,7 @@
<!-- Left Side Of Navbar -->
<ul class="navbar-nav mr-auto">
<a class="nav-link" href="{{ route('google.index') }}">Accounts</a>
<a class="nav-link" href="{{ route('event.index') }}">Events</a>
</ul>
<!-- Right Side Of Navbar -->
@@ -70,6 +70,7 @@
<div class="top-right links">
@auth
<a href="{{ route('google.index') }}">Accounts</a>
<a href="{{ route('event.index') }}">Events</a>
@else
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
View
@@ -21,3 +21,6 @@
Route::name('google.index')->get('google', 'GoogleAccountController@index');
Route::name('google.store')->get('google/oauth', 'GoogleAccountController@store');
Route::name('google.destroy')->delete('google/{googleAccount}', 'GoogleAccountController@destroy');
// Viewing events.
Route::name('event.index')->get('event', 'EventController@index');

0 comments on commit 9989439

Please sign in to comment.