我想在另一个控制器中使用来自1个控制器的数据,比如
class CompanyController extends Controller
{
public function getCompaniesForUser()
{
$companies = $this->company->get();
return $companies; // This does work good and returns the values
}
}
class UserController extends Controller
{
public function test()
{
$companies = $company->getCompaniesForUser();
return $companies;
}
}
但我如何获得$ company-> getCompaniesForUser();在User类中?
答案 0 :(得分:0)
你可以这样做:
in laravel 4.2
App::make('CompanyController')->getCompaniesForUser();
in laravel 5
\App::make('App\Http\Controllers\DocControllerCompanyController')->getCompaniesForUser();
但是建议您阅读此答案Laravel 4 - Use a controller action in other controllers?
使用存储库是一种更好的方法!