Here, we will discuss how to use one function variable to another function. Pass a variable from one function to another in laravel 7, laravel 8,laravel 9. Define a variable in a function and use to another function.
Laravel use one function variable to another function
Here we will take an example of sending a variable to another function and changing its value accordingly. We want to change user birth date format and then make a function dob_format() See below example
class UserController extends Controller{ public function show($id){ $user = User::find($id); $user_dob = $user->dob; $user_dob = $this->dob_format($user_dob); } public function dob_format($user_dob){ return date('d M Y', strtotime($user_dob)); } }