Create a room booking system with Laravel and FullCalendar

laravel 8

Sample code for each function as follows:

Index function:

public function index()
{
  return view('event/list', ['events' => Event::orderBy('start_time')->get()]);
}

Create function:

public function create()
{
  return view('event/create');
}

Store function:

public function store(Request $request)
{
  $time = explode(" - ", $request->input('time'));
 
 $event = new Event;
 $event->name = $request->input('name');
 $event->title = $request->input('title');
 $event->start_time = $time[0];
 $event->end_time = $time[1];
 $event->save();
 
 $request->session()->flash('success', 'The event was successfully saved!');
 return redirect('events/create');
}

Show function:

public function show($id)
{
 return view('event/view', ['event' => Event::findOrFail($id)]);
}

Edit function:

public function edit($id)
{
 return view('event/edit', ['event' => Event::findOrFail($id)]);
}

Update function:

public function update(Request $request, $id)
{
 $time = explode(" - ", $request->input('time'));
 
 $event = Event::findOrFail($id);
 $event->name = $request->input('name');
 $event->title = $request->input('title');
 $event->start_time = $time[0];
 $event->end_time = $time[1];
 $event->save();
 
 return redirect('events');
}

Destroy function:

public function destroy($id)
{
 $event = Event::find($id);
 $event->delete();
 
 return redirect('events');
}

Step 6: Register route controller

You need to register the route for our controller in the routes.php file. You may find the file in app > Http folder and add the code as follows:

Route::resource('events', 'EventController');

By adding this, now you can access the pages via web browser. I will continue this tutorial on Part 2 which will be focusing on the front end. Stay tuned. Click here for the demo. 🙂

The download link is available here.

Update: Part 2 and Part 3.

Update on 11/12/2017 – The demo site is for Room Booking Pro.