Touranmeldung durchführen + zurückziehen
This commit is contained in:
parent
30cdeab510
commit
2f0a54ed77
6 changed files with 71 additions and 14 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Tour;
|
use App\Tour;
|
||||||
|
use App\Booking;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\File;
|
use Illuminate\Http\File;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
@ -177,4 +178,16 @@ class TourController extends Controller
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function join($tour_id) {
|
||||||
|
$user=Auth::user();
|
||||||
|
Tour::join($tour_id,$user->id);
|
||||||
|
return redirect('/tour');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancelBooking($tour_id) {
|
||||||
|
$user=Auth::user();
|
||||||
|
Booking::where('tour_id', $tour_id)->where('user_id', $user->id)->delete();
|
||||||
|
return redirect('/tour');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class Tour extends Model
|
class Tour extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -25,14 +26,22 @@ class Tour extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function join($tour_id,$user_id) {
|
public static function join($tour_id,$user_id) {
|
||||||
|
error_log("Tour::join, tour_id=".$tour_id.", user_id=".$user_id);
|
||||||
|
/*
|
||||||
Booking::firstOrCreate(
|
Booking::firstOrCreate(
|
||||||
['tour_id',$tour_id],
|
['tour_id',$tour_id],
|
||||||
['user_id',$user_id],
|
['user_id',$user_id],
|
||||||
['updated_at', \Carbon::now()]
|
['updated_at', Carbon::now()]
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
$booking = Booking::firstOrCreate(
|
||||||
|
['tour_id' => $tour_id, 'user_id' => $user_id],
|
||||||
|
['tour_id' => $tour_id, 'user_id' => $user_id, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now() ]
|
||||||
|
);
|
||||||
|
error_log($booking);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function leave($tour_id, $user_id) {
|
public static function cancel($tour_id, $user_id) {
|
||||||
Booking::where('tour_id',$tour_id)->where('user_id',$user_id)->delete();
|
Booking::where('tour_id',$tour_id)->where('user_id',$user_id)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,12 @@ class User extends Authenticatable
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function has_tour($tour_id, $user_id) {
|
||||||
|
$tour=Tour::find($tour_id);
|
||||||
|
$user=User::first($user_id);
|
||||||
|
$booking=Booking::where('tour_id', $tour_id)->where('user_id', $user_id);
|
||||||
|
if ($booking) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,38 +13,58 @@ class BookingSeeder extends Seeder
|
||||||
{
|
{
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'tour_id' => 1
|
'tour_id' => 1,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 2,
|
'user_id' => 2,
|
||||||
'tour_id' => 1
|
'tour_id' => 1,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 3,
|
'user_id' => 3,
|
||||||
'tour_id' => 1
|
'tour_id' => 1,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 4,
|
'user_id' => 4,
|
||||||
'tour_id' => 2
|
'tour_id' => 2,
|
||||||
]);DB::table('bookings')->insert([
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 5,
|
'user_id' => 5,
|
||||||
'tour_id' => 2
|
'tour_id' => 2,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 2,
|
'user_id' => 2,
|
||||||
'tour_id' => 3
|
'tour_id' => 3,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 3,
|
'user_id' => 3,
|
||||||
'tour_id' => 3
|
'tour_id' => 3,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 4,
|
'user_id' => 4,
|
||||||
'tour_id' => 3
|
'tour_id' => 3,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
DB::table('bookings')->insert([
|
DB::table('bookings')->insert([
|
||||||
'user_id' => 6,
|
'user_id' => 6,
|
||||||
'tour_id' => 3
|
'tour_id' => 3,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,15 @@
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- TODO: Only if owner or admin -->
|
||||||
<a href="/tour/{{$tour->id}}/edit"><div type="submit" class="btn btn-danger col-3 mb-2 float-left mr-2">Bearbeiten</div></a>
|
<a href="/tour/{{$tour->id}}/edit"><div type="submit" class="btn btn-danger col-3 mb-2 float-left mr-2">Bearbeiten</div></a>
|
||||||
<a href="/tour" type="submit" class="btn btn-success col-3 mb-2 float-right mr-2">Ok</a>
|
<a href="/tour" type="submit" class="btn btn-success col-3 mb-2 float-right mr-2">Ok</a>
|
||||||
<a href="#" type="submit" class="btn btn-danger col-3 mb-2 float-right mr-2">Teilnehmen</a>
|
|
||||||
|
@if(!App\Tour::has_participant($tour->id, Auth::user()->id))
|
||||||
|
<a href="/tour/{{$tour->id}}/join" type="submit" class="btn btn-danger col-3 mb-2 float-right mr-2">Teilnehmen</a>
|
||||||
|
@else
|
||||||
|
<a href="/tour/{{$tour->id}}/cancelBooking" type="submit" class="btn btn-danger col-3 mb-2 float-right mr-2">Absagen</a>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ Route::get('/admin/edit_activities', 'AdminController@edit_activities');
|
||||||
Route::post('/admin/store_activities', 'AdminController@store_activities');
|
Route::post('/admin/store_activities', 'AdminController@store_activities');
|
||||||
|
|
||||||
Route::resource('/tour', TourController::class);
|
Route::resource('/tour', TourController::class);
|
||||||
|
Route::get('/tour/{tour_id}/join', 'TourController@join');
|
||||||
|
Route::get('/tour/{tour_id}/cancelBooking', 'TourController@cancelBooking');
|
||||||
|
|
||||||
Auth::routes();
|
Auth::routes();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue