mercredi 27 juillet 2016

Laravel - how to deal with controller extends another controller

I'm having Laravel app that have two controllers UserController an AdminController , ofcourse Admin have more credentials than user and here comes my question:

I want User to be able to:

  1. fetch and view account
  2. fetch and view mail

and Admin to be able to:

  1. fetch and view account
  2. fetch and view mail
  3. manage account
  4. manage mail

obviously there is redundant in the fetching and viewing functionality for both, so I tried to creating two controllers. the AdminController extends 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
         ***/
 }

how can I use the fetching and viewing functions of UserController in AdminController?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire