vendredi 24 juin 2016

Laravel 5.2 Controller returning an object

I am having problems with a controller returning just an object. I have a tables types and in TypesController I want a function that will just return an array of types so I can use it in another controller so I wrote in TypesController:

public function getNavTypes()
    {
        $types = DB::table('v_itemtypes')->get();
        return ($types);
    }

I want to call this in another controller (authors) so I added the line

use App\Http\Controllers\TypeController;

And want to just call the object in my method to pass on to the view:

 public function getAuthor($author_id)
    {

        $author = Author::where('id', $author_id)->first();
        $navtypes = TypeController::getNavTypes;
        return view('authors.edit',['author'=>$author, 'navtypes'=>$navtypes]);
    }

but I am getting the following error:

FatalErrorException in AuthorController.php line 28: Undefined class constant 'getNavTypes'

Line 28 is

$navtypes = TypeController::getNavTypes;

As a newbie I am doing something wrong, but what?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28Tn3LB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire