From 30cdeab510a05102a0c66127d26ad551040e155a Mon Sep 17 00:00:00 2001 From: TorstenS Date: Wed, 7 Oct 2020 22:18:54 +0200 Subject: [PATCH] Working on Tour Booking --- motorradig/app/Tour.php | 22 +++++++- .../2020_09_30_082629_create_tours_table.php | 1 + motorradig/database/seeds/TourSeeder.php | 3 ++ .../resources/views/tour/index.blade.php | 10 +++- .../resources/views/tour/show.blade.php | 53 +++++++++++-------- 5 files changed, 64 insertions(+), 25 deletions(-) diff --git a/motorradig/app/Tour.php b/motorradig/app/Tour.php index 197f33b..f33c539 100644 --- a/motorradig/app/Tour.php +++ b/motorradig/app/Tour.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Tour extends Model { protected $fillable = [ - 'id', 'name', 'beschreibung','user_id','start','deadline' + 'id', 'name', 'beschreibung','user_id','start','deadline','is_cancelled', 'status' ]; public static function getBookings($tour_id) { @@ -15,4 +15,24 @@ class Tour extends Model $bookings=Booking::where('tour_id',$tour_id)->get(); return $bookings; } + + public static function has_participant($tour_id, $user_id) { + $booking=Booking::where('tour_id', $tour_id)->where('user_id',$user_id)->first(); + + if($booking) return true; + + return false; + } + + public static function join($tour_id,$user_id) { + Booking::firstOrCreate( + ['tour_id',$tour_id], + ['user_id',$user_id], + ['updated_at', \Carbon::now()] + ); + } + + public static function leave($tour_id, $user_id) { + Booking::where('tour_id',$tour_id)->where('user_id',$user_id)->delete(); + } } diff --git a/motorradig/database/migrations/2020_09_30_082629_create_tours_table.php b/motorradig/database/migrations/2020_09_30_082629_create_tours_table.php index ad9f84d..a137fde 100644 --- a/motorradig/database/migrations/2020_09_30_082629_create_tours_table.php +++ b/motorradig/database/migrations/2020_09_30_082629_create_tours_table.php @@ -22,6 +22,7 @@ class CreateToursTable extends Migration $table->date('start')->nullable(); $table->date('deadline')->nullable(); $table->boolean('is_cancelled')->default(false); + $table->string('status')->default('FINDET STATT'); $table->timestamps(); }); } diff --git a/motorradig/database/seeds/TourSeeder.php b/motorradig/database/seeds/TourSeeder.php index 5e1a147..11ad566 100644 --- a/motorradig/database/seeds/TourSeeder.php +++ b/motorradig/database/seeds/TourSeeder.php @@ -16,6 +16,7 @@ class TourSeeder extends Seeder 'name' => 'Eifeltour1', 'user_id' => 3, 'start' => Carbon::parse('2020-11-11'), + 'deadline' => Carbon::parse('2020-11-01'), 'is_cancelled' => false, 'beschreibung' => 'Hier kann ein sehr langer Text stehen.' ]); @@ -25,6 +26,7 @@ class TourSeeder extends Seeder 'user_id' => 2, 'beschreibung' => 'Hier kann ein sehr langer Text stehen.', 'start' => Carbon::parse('2020-12-01'), + 'deadline' => Carbon::parse('2020-11-02'), 'is_cancelled' => false, ]); @@ -33,6 +35,7 @@ class TourSeeder extends Seeder 'user_id' => 1, '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'), 'is_cancelled' => true ]); diff --git a/motorradig/resources/views/tour/index.blade.php b/motorradig/resources/views/tour/index.blade.php index c2267d4..7a32160 100644 --- a/motorradig/resources/views/tour/index.blade.php +++ b/motorradig/resources/views/tour/index.blade.php @@ -6,12 +6,20 @@ Download -
+
.