Use a model instance in different controller - Laravel 5

Rápli András

There is a HomeController in app/Http/Controllers and a Player model in app.

HomeController:

namespace App\Http\Controllers;

Player:

namespace App;
use Illuminate\Database\Eloquent\Model;

Double-checked, the Player model gets PSR-4 autoloaded. I've tried to use various versions in HomeController, but it keeps trying to look for Eloquent class (which Player extends) in wrong paths. Also, in the tested HomeController method, instantiating the model is foggy, do I need to prefix the namespace now? because with or without use command it does not work.

Rápli András

Realized that I had to alias this path to Eloquent to make it work:

use Illuminate\Database\Eloquent\Model as Eloquent;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Laravel Controller update model from different users

How to use different Auth for different controller in Laravel

laravel 5 load model on every controller

laravel 5 how to pass data to controller to model

Laravel 5 Eloquent Model Object in AngularJS Controller

Ruby on Rails: finding a model instance from a different controller

Laravel 5 - Use variables of model in model factories

codeigniter - use model results in controller to call a different function in the model

How to use scope of a model, in a different model's controller in rails 4

how to use different namespaces in a controller in laravel 4.1

Laravel controller return model instance instead data content

Modify Laravel model response to use different ID

How to use a controller inside another controller in Laravel5 as service

How to call a model function inside the controller in Laravel 5

Laravel 5 : Use different database for testing and local

Laravel get instance in a model

Laravel 5 Entrust one route - load different controller based on Role

model e controller laravel

Laravel Function : In controller or in model?

How to use same url in routes for 2 different controller methods in a Laravel?

Laravel4: Use different model depending on config

How to use Token number in all controller and view pages in laravel 5?

Laravel 5 Validation in controller

Creating a Model in Rails within the controller of a different Model

Laravel 4 / 5: Make `return Model` automatically use HTML view

Laravel: pluck method on Model instance

Change controller model template in Laravel

Troubleshooting referencing a model in a laravel controller

Laravel function belong in model or controller