Access variable from other function LARAVEL -
i'm trying use returned result function function. here first function:
public function availablerooms(){ if(isset($_post['selecteddate'])){ $checkindatereceived = str_replace('/', '-', $_post['selecteddate']); $checkindate = date('y-m-d', strtotime($checkindatereceived)); $availablerooms = db::table('rooms') ->leftjoin('reservations', function ($secondjoin) use($checkindate) { $secondjoin->where('reservations.checkout_date', '<', $checkindate); }) ->leftjoin('reservation_room_rel', function ($firstjoin) { $firstjoin ->on('reservation_room_rel.room_id', '=', 'rooms.id') ->on('reservation_room_rel.reservation_id', '=', 'reservations.id'); }) ->where([ ['rooms.status', '=', 1] ]) ->wherenull('reservation_room_rel.room_id') ->get(); return $availablerooms; } }
and here second function:
public function returnaddreservation(){ $availableroomsret = $this->availablerooms(); $mealsupplement = new meal; $accommodationsupplement = new accommodationsupplement; $accommodationsupplements = $accommodationsupplement::where('status', 1) ->orderby('name', 'asc') ->get(); $mealsupplements = $mealsupplement::where('status', 1) ->orderby('name', 'asc') ->get(); return view('addreservation', [ 'availablerooms' => $availableroomsret, 'accommodationsupplements' => $accommodationsupplements, 'mealsupplements' => $mealsupplements ]); }
first function returns correct result if runs independently, but, when dd($availableroomsret)
it returns null. idea how access $availablerooms
public function availablerooms()
public function returnaddreservation()
? thanks!
as long in same class should value nothing related laravel pure php.
you can try doing so
public function availablerooms(){ $availablerooms = 15; return $availablerooms; } public function returnaddreservation(){ var_dump('inside class'. $this->availablerooms()); $availableroomsret = $this->availablerooms(); return $availableroomsret; } public function thirdfunction(){ var_dump('inside third function' . $this->returnaddreservation()); }
Comments
Post a Comment