user1012181
user1012181

Reputation: 8726

Creating a public function inside a controller in Laravel

I'm trying to create a public/private function inside my controller (say PostController) to tidy up certain code.

I wrote something like this:

class PostController extends BaseController
{      
    public function store()
    {
        $startdate = dateformatchange(Input::get('startdate'));
    }

    public function dateformatchange($date)
    {
        $dateString = DateTime::createFromFormat('m-d-Y', $date);
        $dateNew = $dateString->format('Y/m/d');
        return $dateNew;
    }     
}

But I'm getting some error. Call to undefined function dateformatchange()

Am I doing it wrong? please advice where I went wrong. Sorry if it is a silly mistake.

Upvotes: 2

Views: 462

Answers (1)

Laurence
Laurence

Reputation: 60048

You need to do it like this:

$startdate = $this->dateformatchange(Input::get('startdate'));

Upvotes: 4

Related Questions