Ad

Same Views In Different Profiles Laravel

I am new to laravel. I am developing a medical aplication using laravel 6. I have used laravel auth and middleware to control users and profiles. I have 4 profiles (admin, physical doctor, doctor and nurse). I need that the admin and the physical doctor have the same dashboard (main screen). Does anyone know how to do that?

This is my routes file web.php:

Route::get('/', function () {
    return view('auth.login');
});

Auth::routes();

Route::group(['as'=>'admin.','prefix'=>'admin','namespace'=>'admin', 'middleware'=>['auth','admin']], function ()
{
    Route::get('dashboard', '[email protected]')->name('dashboard');
    Route::resource('user', 'UserController');
    Route::resource('dosimeter', 'DosimeterController');
    Route::resource('dosimeterref', 'DosimeterRefController');
    Route::resource('room', 'RoomController');
});

Route::group(['as'=>'mphysicist.','prefix'=>'mphysicist','namespace'=>'mphysicist', 'middleware'=>['auth','mphysicist']], function ()
{
    Route::get('dashboard', '[email protected]')->name('dashboard');
});

Route::group(['as'=>'doctor.','prefix'=>'doctor','namespace'=>'doctor', 'middleware'=>['auth','doctor']], function ()
{
    Route::get('dashboard', '[email protected]')->name('dashboard');
});

Route::group(['as'=>'nurse.','prefix'=>'nurse','namespace'=>'nurse', 'middleware'=>['auth','nurse']], function ()
{
    Route::get('dashboard', '[email protected]')->name('dashboard');
});

This is my views foldes:

enter image description here

And this is my Controller folders:

enter image description here

This is my admin dashboard code:

<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\DosimeterRef;
use App\Room;
use App\DoseRecordReference;
use Illuminate\Support\Facades\DB;

class DashboardController extends Controller
{
    public function index(Request $request)
    {
        $rooms = Room::all();
        $dosiemterrefs = DosimeterRef::all();
        $doseRecordReferences = DoseRecordReference::all();


        $period = $request->get('period_form');

        if(empty($period) || is_null($period) || $period == 0){
          $dosim_info_array = self::getRoomDosimData(1);
        } else {
          $dosim_info_array = self::getRoomDosimData($period);
        }


        return view('admin.dashboard',compact('rooms','dosiemterrefs', 'doseRecordReferences', 'period', 'dosim_info_array'));
    }
//Other functions
}

And this is my physical doctor dashboard:

<?php

namespace App\Http\Controllers\MPhysicist;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        return view('mphysicist.dashboard');
    }
}

I need both dashboards to be the same in order to avoid repeating code.

Thank you so much and sorry if the question is too easy, I am new to laravel.

Ad

Answer

If you want to get the same Blade view, you just have to remove the prefix from the view name

Before

return view('mphysicist.dashboard');

After

return view('dashboard');

The value you give to view helper is a dotted-path starting from your views folder. By the way, you should move the common Blade file in order to not be namespaced.

Ad
source: stackoverflow.com
Ad