vendredi 5 octobre 2018

Laravel how to send same variable to all views for different type of users logged in

I have three types of users in my laravel web application (Admin, Teacher, Student). I want to send different variable to all views for different users. To do this I made a parent controller BaseController which is extended by every controller. In the constructor of this controller I write following code.

?php
namespace App\Http\Controllers;
use App\Navigation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class BaseController extends Controller
{
   public function __construct()
   {
     $user_type='';
     if (Auth::guard('web')->check()) {
         $user_type = 'admin';
     } elseif (Auth::guard('teacher')->check()) {
         $user_type = 'teacher';
     } elseif (Auth::guard('student')->check()) {
         $user_type = 'student';
     }
     $nav = Navigation::items($user_type);
     view()->share('nav', $nav);
   }
 }

I really need help their guys.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire