diff --git a/motorradig/app/Http/Controllers/TourController.php b/motorradig/app/Http/Controllers/TourController.php index 423271b..35d18ea 100644 --- a/motorradig/app/Http/Controllers/TourController.php +++ b/motorradig/app/Http/Controllers/TourController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Tour; use App\Booking; use App\User; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\File; use Illuminate\Support\Facades\Storage; @@ -22,7 +23,7 @@ class TourController extends Controller public function index() { error_log("Tour:index"); - $tours=Tour::all(); + $tours=Tour::where('start','>',Carbon::now())->get(); $participantCount=array(); foreach($tours as $tour) { $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); @@ -31,6 +32,19 @@ class TourController extends Controller return view('tour.index')->with('tours',$tours)->with('participantCount',$participantCount); } + public function index_old() + { + error_log("Tour:index_old"); + $tours=Tour::where('start','<',Carbon::now())->get(); + $participantCount=array(); + foreach($tours as $tour) { + $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); + $participantCount[$tour->id] = $result[0]->cnt; + } + return view('tour.index_old')->with('tours',$tours)->with('participantCount',$participantCount); + } + + /* @@ -206,4 +220,5 @@ class TourController extends Controller return redirect('/tour/'.$tour_id); } + } diff --git a/motorradig/app/Tour.php b/motorradig/app/Tour.php index 0b200fa..5721476 100644 --- a/motorradig/app/Tour.php +++ b/motorradig/app/Tour.php @@ -44,4 +44,10 @@ class Tour extends Model public static function cancel($tour_id, $user_id) { Booking::where('tour_id',$tour_id)->where('user_id',$user_id)->delete(); } + + public static function is_over($tour_id) { + $tour = Tour::find($tour_id); + if ($tour->start < Carbon::now()) return true; + return false; + } } diff --git a/motorradig/database/seeds/TourSeeder.php b/motorradig/database/seeds/TourSeeder.php index 11ad566..be54b33 100644 --- a/motorradig/database/seeds/TourSeeder.php +++ b/motorradig/database/seeds/TourSeeder.php @@ -12,12 +12,23 @@ class TourSeeder extends Seeder */ public function run() { + DB::table('tours')->insert([ + 'name' => 'Moseltour', + 'user_id' => 3, + 'start' => Carbon::parse('2019-06-11'), + 'deadline' => Carbon::parse('2019-05-30'), + 'is_cancelled' => false, + 'max_participants' => 8, + 'beschreibung' => 'Erster Versuch einer Moseltour.' + ]); + DB::table('tours')->insert([ 'name' => 'Eifeltour1', 'user_id' => 3, 'start' => Carbon::parse('2020-11-11'), 'deadline' => Carbon::parse('2020-11-01'), 'is_cancelled' => false, + 'max_participants' => 7, 'beschreibung' => 'Hier kann ein sehr langer Text stehen.' ]); @@ -27,6 +38,7 @@ class TourSeeder extends Seeder 'beschreibung' => 'Hier kann ein sehr langer Text stehen.', 'start' => Carbon::parse('2020-12-01'), 'deadline' => Carbon::parse('2020-11-02'), + 'max_participants' => 6, 'is_cancelled' => false, ]); @@ -36,10 +48,9 @@ class TourSeeder extends Seeder 'beschreibung' => 'Hier kann ein wirklich sehr langer Text stehen.
Es sind auch mehrere Abschnitte möglich.', 'start' => Carbon::parse('2020-12-15'), 'deadline' => Carbon::parse('2020-11-15'), + 'max_participants' => 5, 'is_cancelled' => true ]); } } - - diff --git a/motorradig/resources/views/tour/index.blade.php b/motorradig/resources/views/tour/index.blade.php index ce340e3..a5f58ff 100644 --- a/motorradig/resources/views/tour/index.blade.php +++ b/motorradig/resources/views/tour/index.blade.php @@ -2,8 +2,20 @@ @section('content')