Tower
Tower

Reputation: 345

Laravel shows blank page as the view

I have created a function in my HomeController.php beside the index method in Laravel 5.3. In the index method, there are some data retrieved from database, and the sent to the other method to be analyzed and sent to the home view to be shown.
My problem is that laravel displays a mere blank page instead of the actual home.blade.php view. Below is the code that I am using to retrieve data from database and send them to the view. Could you please tell me what am I doing wrong here?

public function index ()
{
    $user_table_data = DB::table($table_name)->get();           
    $this->ChooseAction($user_table_data);
}

private function ChooseAction ($r_value)
    {

        foreach ($r_value[0] as $key => $value)
        {
            if ( $key !=='id' && $value !== '0' )
            {
                array_push($this->choose_action_result, $key);
            }
        }        

        if (!empty($this->choose_action_result))
        {
            return view('home', ['rvalue' => $this->choose_action_result]);
        }else{
            return view('home');
        }

    }

Upvotes: 0

Views: 979

Answers (2)

Robin Dirksen
Robin Dirksen

Reputation: 3422

This will be your code:

public function index ()
{
    $user_table_data = DB::table($table_name)->get();           
    return $this->ChooseAction($user_table_data); //here you also need a return
}

private function ChooseAction ($r_value)
{

    foreach ($r_value[0] as $key => $value)
    {
        if ( $key !=='id' && $value !== '0' )
        {
            array_push($this->choose_action_result, $key);
        }
    }        

    if (!empty($this->choose_action_result))
    {
        return view('home', ['rvalue' => $this->choose_action_result]);
    }else{
        return view('home');
    }

}

You didn't return the view in your public function index() {} that you got from your private method.

Upvotes: 1

Sagar Rabadiya
Sagar Rabadiya

Reputation: 4321

in your index method return the call of private value

public function index ()
{
    $user_table_data = DB::table($table_name)->get();           
    return $this->ChooseAction($user_table_data);
}

mark the return keyword in the call statement if should return the view

Upvotes: 2

Related Questions