我的Laravel应用程序有两个控制器UserController
和AdminController
,当然管理员拥有的凭据多于用户,这就是我的问题:
我希望用户能够:
和管理员能够:
显然,两者的获取和查看功能都有多余,所以我尝试来创建两个控制器。 AdminController
延伸 UserController
:
UserController
:
?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use DB;
use App\Http\Requests;
use App\User;
use App\Account;
use App\Mail;
class UserController extends Controller
{
/*******************
* Helper functions
* retrieving data
***/
//retrieving data from database
protected function getaccount($userId){
//fetch data from database
}
protected function getmail($userId){
//fetch mail from database
}
/*******************
*other controller functions
***/
}
AdminController
:
?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use DB;
use App\Http\Requests;
use App\User;
use App\Account;
use App\Mail;
class AdminController extends Controller, UserController
{
/*******************
* Helper functions
* retrieving data
***/
//retrieving data from database
protected function manageaccount($userId){
//manage
}
protected function managemail($userId){
//manage
}
/*******************
*other controller functions
***/
}
如何<{1}}中使用UserController
的提取和查看功能?
答案 0 :(得分:0)
您可能希望将getaccount
和getmail
方法放在User
模型类上。