Booking a room








  • Create the deployment diagram  of the application


Part 1 – Availability

Deliverable gitlab : otelo/mission6/…

  • check that the category foreign key of the room table is called category_id
  • display the rooms of a category
class Chambre extends Model{
  public function categorie(){
    return $this->belongsTo('App\Categorie');

class Categorie extends Model{
  public function chambres(){
  return $this->hasMany('App\Chambre');

dans controleur

$categorie = Categorie::where('id',3)->->firstOrFail();
//obtention des chambres
$chambres=$categorie ->chambres();
//renvoie vers vue puis foreach ou dd($categorie ->chambres())

//obtention de la categorie d'une chambre 
//$chambre = Chambre::where('id',1)->firstOrFail(); 
  • Create the URI GET availabilities which sends back the list of available rooms according to the start date, the end date and the category in JSON.
public function dispo()
        $chambres = DB::select('select, nbCouchage, porte, etage,libelle ,baignoire from chambre inner join categories on chambre.categorie_id =
        where chambre.categorie_id=? and      not in (select reservation.idChambre from reservation where
               dateD<? or dateF>?)', [3,'2021-03-03', '2021-03-01'] );
       // return view('chambres',['chambres' => $chambres]);
       return response()->json($chambres);

  • Each line must show the basic price per day and the description of the room. See note to get all the rooms of a category

Part 2 – research

Deliverable gitlab : otelo/mission6/…

  • Create the form to search for a room by start date, end date and room category.
  • Display the answer. Each line should show the basic price per day and the description of the room.

Part 3 – booking

Deliverable gitlab : otelo/mission6/…

  • enable the booking of a room and register it in the database

@create (creation form)

@[email protected]
   $chambres = chambres ();
  return view('reservation.create', ['chambres ' => $chambres ]);

Route::get('reservation/new',[ReservationController::class, 'create'] )->name('reservation.create');

   @foreach($chambres as $chambre)

@store  (reception of the form create)

Route::post('reservation/store', [ReservationController::class, 'store'])->name('');

@[email protected]

$reservation=new Reservation();
$reservation->description= $request->input('description');

return redirect()->route('zaza')->with('success','réservation enregistrée');;




Note :


@[email protected]
   $chambres= Chambre::findAll();
  return view('chambre.index', ['chambres' => $chambres]);

Route::get('/chambres', [ReservationController::class, 'index'])->name('chambre.index');

  @foreach($categories as $categorie)


@[email protected]
   $categories = Categories:all();
  return view('chambre.create', ['categories ' => $categories ]);

Route::get('chambre/new', [ReservationController::class, 'create'])->name('chambre.create');

   @foreach($categories as $categorie)

@store and Image storage (create form reception)

form input for image storage, don’t forget enctype in form


<form action="#" method="POST" enctype="multipart/form-data">
  <input type="file" name="image"/>


Route::post('chambre/store', [ReservationController::class, 'store'])->name('');


Symbolic link between storage folder and public folder of the site so that the images are publicly accessible

php artisan storage:link
php artisan cache:clear


@[email protected]

$chambre=new Chambre();
$chambre->description= $request->input('description');

$image= $request->file("image");
$imageFullName = $image->getClientOriginalName();
$imageName= pathinfo($imageFullName, PATHINFO_FILENAME);
$imageExtension= $image->getClientOriginalExtension();
$file = time() . '_' . $imageName . '.' .  $imageExtension;

$chambre->image = $file;

return redirect()->route('zaza')->with('success','chambre enregitrée');


<img class="mon-image"



 <a href="{{route('chambre.edit', $chambre->id)}}">

@[email protected]
  $chambre= Chambre::find($id);
  return view('chambre.edit', ['chambre' => $chambre]);

Route::get('chambre/{id}/edit', [ReservationController::class, 'edit'])->name('chambre.edit');


@update and Image storage (edit form reception)

Route::put('chambre/{id}/update', [ReservationController::class, 'update'])->name('chambre.update');

    <form action="{{route('chambre.update', $chambre->id)}} method="POST"

@[email protected] 
  $chambre= Chambre::find($id); 
      $image= $request->file("image"); 
      $imageFullName = $image->getClientOriginalName(); 
      $imageName= pathinfo($imageFullName, PATHINFO_FILENAME); 
      $file = time() . '_' . $imageName . '.' . $imageExtension; $image-     >storeAs('public/chambres/',$file); 
      $chambre->image = $file;

  return redirect()->route('chambre.index');


Route::delete('chambre/{id}/destroy', [ReservationController::class, 'destroy'])->name('chambre.destroy');

@lien de suppression
<a href="{{route('chambre.destroy', $chambre->id)}}"></a>

@[email protected]
  $chambre= Chambre::find($id); 
  return redirect()->route('chambre.index')->with('success','chambre supprimée');


Environment variable