php - Laravel view rendering issue

288

Following is my controller class,

namespace Admin;
class CategoriesController extends \BaseController {

    public function index($action = '', $id= ''){
       //return \View::make('welcome');View is correctly rendered here
        switch ($action){
            case ''     :
            case 'list' : $this->showList();
            break;
            case 'add'  : $this->addCategories();
            break;
            case 'edit' : $this->editCategories($id);
            break;
        }

    }

    public function showList($id_category =''){
        echo "testing";
        return \View::make('welcome'); //it does not work here
   }

While calling the view, it does not work within the function showList(). The echo inside the function works, but the view just return a blank page without any errors. What could be the issue here?

496

Answer

Solution:

I imagine you want to callshowList from theindex function and not from the routes. If so, there's no return action from theindex function. In order to make it work, you need to return within theindex function what is returned fromshowList function, otherwise, the View will not be rendered. Try changing yourindex function to:

public function index($action = '', $id= '') {
    switch ($action) {
        case ''     :
        case 'list' : 
                    return $this->showList();
        case 'add'  : 
                    return $this->addCategories();
        case 'edit' : 
                    return $this->editCategories($id);
    }

}
493

Answer

Solution:

here is the problem...remove the / from the return view line

public function showList($id_category =''){
    echo "testing";
    return View::make('welcome'); //it does not work here

}

People are also looking for solutions to the problem: performance - PHP file uploads. POST vs PUT?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.