How to use one function variable to another function in laravel

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));
  }
}
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links