Luiz Pinheiro
Luiz Pinheiro

Reputation: 23

Call function using more than one variable. PHP - Laravel - Blade

I'm trying to call one function (get the week day(is working)) that I've made on Controller e needed two variables. But when I call from the view (using Blade from Laravel) I got the message that I'm passing only one atribute, instead two.

My control:

public function getWeekDay($monthYear, $qtdDay){ 

    $month = substr($monthYear, 0, 2);
    $year= substr($monthYear, 3, 4);
    $month = $month + 1;

    $lastDay = date('m/d/Y', mktime(0, 0, 0, $month, 0, $year));

    $firstDay = strtotime($lastDay . ' +'.$qtdDay.' Weekday');

   return date('d/m/Y', $firstDay);
}

My view:

{!! app(App\\Http\\Controllers\\Site\\TarefaController::class)->getWeekDay( [$monthYear , $qtdDay ) }}

Is it the way that I should call function from Blade??

Upvotes: 0

Views: 607

Answers (2)

Sreejith BS
Sreejith BS

Reputation: 1203

Make the function as static.

public static function getWeekDay($monthYear, $qtdDay){ //** static

    $month = substr($monthYear, 0, 2);
    $year= substr($monthYear, 3, 4);
    $month = $month + 1;

    $lastDay = date('m/d/Y', mktime(0, 0, 0, $month, 0, $year));

    $firstDay = strtotime($lastDay . ' +'.$qtdDay.' Weekday');

   return date('d/m/Y', $firstDay);
}

In your view call

{{ \App\Http\Controllers\Site\TarefaController::getWeekDay($monthYear, $qtdDay) }}

Hope it works.

Upvotes: 0

Remco K.
Remco K.

Reputation: 717

You are sending the parameters as one array now

{!! app(App\\Http\\Controllers\\Site\\TarefaController::class)->getWeekDay( [$monthYear , $qtdDay ) }}

Change into

{!! app(App\\Http\\Controllers\\Site\\TarefaController::class)->getWeekDay( $monthYear , $qtdDay ) }}

Upvotes: 1

Related Questions