0

Relatively new to the Laravel framework, and I can't figure out why the function is returning a blank page.

<?php

class MainController extends Controller {

public function setLanguage($language = 'nl', $page = 'index')
{
    switch ($language) {
        case 'nl':
            $this->showNL();
            break;
        case 'fr':
            echo $language . ' ' . $page;
            break;
        case 'de':
            echo $language . ' ' . $page;
            break;
        default:
            echo "nothing here";
    }
}

public function showNL() {
    return "Display some text";
}

}

The function showNL() is called but it just returns an empty html document. Also no laravel errors.

2 Answers 2

3

You do nothing with the output of showNL()

try doing:

return $this->showNL();

Also: never echo or print anything in controller methods, always return the output, so you should change all your switch statements.

Sign up to request clarification or add additional context in comments.

Comments

2

Shoudn't it be ?

   switch ($language) {
        case 'nl':
            echo $this->showNL(); // Added echo

1 Comment

No, you should never print anything in controller methods.

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.