0

There are two Mysql tables:


1.reservations(id,screening_id,reserved). the reserved is a boolean its value "1".


  1. table seat_reserveds(id,screening_id,reservation_id,seat_id).

I want the following: 1.get the reservation id select id from reservation where screening_id = id and reserved = 1 In laravel looks like:

          $reservation_id = DB::table('reservations')->select('id')- 
          >where('screening_id',$id)->where('reserved','1')->get();

Then I want to count how many seats are reserved


Select count(id) from seat_resrveds where where screening_id = id and reservtain_id = id. In laravel looks like:

        $reservedtickets = DB::table('seat_reseverds')- 
       >where('screening_id',$id)->where('reservation_id',$reservation_id)->count('id');

I think the problam is that I get "id":number from $reservation_id so cant use it at the $reservedtitckets query because I only need a number. How can I write these querys.

2 Answers 2

1

Use ->value('id') to get a single value from a query:

$reservation_id = DB::table('reservations')
    ->where('screening_id',$id)
    ->where('reserved','1')
    ->value('id');
Sign up to request clarification or add additional context in comments.

1 Comment

@Blasanka - It's not even "eloquent" - It's just the query builder.
0

Update the query to the following.

    $reservation = DB::table('reservations')
      ->where('screening_id',$id)
      ->where('reserved', 1)
      ->first();

Then the $reservation_id should be as below.

$reservation_id = $reservation->id;

You can pass this parameter to your next query for $reservedtickets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.