Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jordantsap's avatar

How to structure existing project for cityguide that also need booking

How to structure and implement existing Laravel project for my community cityguide (https://nea-karvali.gr/en) with booking rooms and ordering products functionality. Ordering products and crud functionalities for every model is done but community is expanding and since last year it also needs booking functionality for rooms that belong to a hotel or other accommodation type included in my community. Booking rooms has different fields than ordering products. I also need different controllers and views for different user roles. Currently there are CompanyType model with seeders that include Rentals as Hotels and different model +seeders+etc for products Github repo https://github.com/jordantsap/karvali Please include guide on how to structure relations between CompanyTypes and hotels, Products and rooms if needed because I'll have to show them somehow in the frontend blade files

Anyone wants to install it consider that: change to any translatable.locales if error Astrotomic\Translatable\Locales::current(): Return value must be of type string, null returned, during running seeders. After seeding return this value to any locale

0 likes
1 reply
LaryAI's avatar
Level 58

To structure and implement your existing Laravel project for a city guide with booking functionality, you can follow these steps:

  1. Create a new model for rooms:

    • Run the following command to generate a new model and migration file: php artisan make:model Room -m
    • In the migration file, define the necessary fields for the rooms (e.g., room number, type, price, availability, etc.).
    • Run the migration to create the rooms table: php artisan migrate
  2. Create a new model for bookings:

    • Run the following command to generate a new model and migration file: php artisan make:model Booking -m
    • In the migration file, define the necessary fields for the bookings (e.g., room_id, user_id, check-in date, check-out date, etc.).
    • Run the migration to create the bookings table: php artisan migrate
  3. Define relationships between models:

    • In the Room model, define a one-to-many relationship with the Booking model:
      public function bookings()
      {
          return $this->hasMany(Booking::class);
      }
      
    • In the Booking model, define a many-to-one relationship with the Room model:
      public function room()
      {
          return $this->belongsTo(Room::class);
      }
      
  4. Create controllers and views for rooms and bookings:

    • Generate a controller for rooms: php artisan make:controller RoomController
    • Generate a controller for bookings: php artisan make:controller BookingController
    • Create the necessary views for rooms and bookings in the resources/views directory.
  5. Implement different controllers and views for different user roles:

    • You can use Laravel's built-in authentication system or a package like Laravel Breeze or Laravel Jetstream to handle user authentication and roles.
    • Based on the user's role, you can conditionally load different controllers and views using middleware or conditional statements in your routes or controllers.
  6. Update the existing controllers and views:

    • Modify the existing controllers and views to accommodate the new booking functionality.
    • You may need to update the routes, forms, and database queries to handle the booking-related operations.
  7. Test the functionality:

    • Use the existing seeders or create new seeders to populate the rooms and bookings tables with sample data.
    • Test the booking functionality by creating, updating, and deleting bookings through the application's UI.

Remember to backup your code and database before making any changes. It's also a good practice to use version control (e.g., Git) to track your changes and easily revert if needed.

Note: The provided solution assumes a basic understanding of Laravel and its concepts. It's recommended to refer to the Laravel documentation for more detailed information on each step.

Please or to participate in this conversation.