0

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??

1
  • Where is th closing ]? And why you use []? Commented Sep 2, 2017 at 14:23

2 Answers 2

1

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 ) }}
Sign up to request clarification or add additional context in comments.

1 Comment

I removed the [, it was wrong.. but still not working!!
0

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.

5 Comments

I changed the view and controller, but still not working. I got the message: Type error: Too few arguments to function App\Http\Controllers\Site\TarefaController::getWeekDay(), 1 passed (view with error) and exactly 2 expected
Are $monthYear, $qtdDay both have values when you pass them in view?
Yes, actually I'm using the same variable that I'm using to make the table.
Try {{ dd($monthYear) }} and {{ dd($qtdDay) }} inside view above that call and see what values.
{{ dd($monthYear) }} I've got "06/2016" , and {{ dd($qtdDay) }} I've got "2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.