Made it possible to sign up for events.
Added fail and success messages when signing up. Fixed unique keys in migrate
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\UserEvent;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
@@ -13,12 +14,28 @@ class UserEventController extends Controller
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $userid
|
||||
* @param int $eventid
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request, $userid, $eventid)
|
||||
public function create(Request $request)
|
||||
{
|
||||
// Get written data from events.index
|
||||
$data = $request->validate([
|
||||
"user_id" => "required|max:255",
|
||||
"event_id" => "required|max:255"
|
||||
]);
|
||||
|
||||
// Check the UserEvent table if there is a row that has the user_id AND the event_id
|
||||
$getTableInfo = UserEvent::where('user_id', $request->user_id)
|
||||
->where('event_id', $request->event_id)->get();
|
||||
|
||||
// If the row has both, then go back and show an error - Cause you're not allowed to be on the same event twice.
|
||||
if (count($getTableInfo) > 0)
|
||||
return redirect()->route("events.index")->with('error#' . $request->event_id, '<p class="text-center">Du har allerede tilmeldt dig denne Aktivitet!</p>');
|
||||
|
||||
// If not, then it keeps going and saves and shows a success message
|
||||
$UserEvent = new UserEvent($data);
|
||||
$UserEvent->save();
|
||||
|
||||
return redirect()->route("events.index")->with('signup#' . $request->event_id, '<p class="text-center">Du er hermed tilmeldt denne aktivitet!</p>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserEvent extends Model
|
||||
{
|
||||
//
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
//protected variable which contains name of database field(s) to be filled.
|
||||
protected $fillable = [
|
||||
'user_id', 'event_id'
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user