Commit 86331fe6 by Shaganaz

Created register,login, logout functionality,user list page,project creation page

parent 9fc8982e
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
.env .env
.env.backup .env.backup
.env.production .env.production
.phpactor.json
.phpunit.result.cache .phpunit.result.cache
Homestead.json Homestead.json
Homestead.yaml Homestead.yaml
...@@ -16,4 +17,4 @@ npm-debug.log ...@@ -16,4 +17,4 @@ npm-debug.log
yarn-error.log yarn-error.log
/.fleet /.fleet
/.idea /.idea
/.vscode /.vscode
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Role;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class AdminUserController extends Controller
{
public function index()
{
$users = User::with('role')->get();
$roles = Role::all();
return view('admin.users', compact('users', 'roles'));
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|string|min:6',
'designation' => 'nullable|string|max:255',
'role_id' => 'required|exists:roles,id',
]);
$validated['password'] = Hash::make($validated['password']);
User::create($validated);
return redirect()->route('admin.users')->with('success', 'User created successfully.');
}
}
...@@ -29,7 +29,13 @@ public function store(LoginRequest $request): RedirectResponse ...@@ -29,7 +29,13 @@ public function store(LoginRequest $request): RedirectResponse
$request->session()->regenerate(); $request->session()->regenerate();
return redirect()->intended(RouteServiceProvider::HOME); $user=auth()->user();
if($user->role->name==='admin'){
return redirect()->route('admin.dashboard');
}
else{
return redirect()->route('user.dashboard');
}
} }
/** /**
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules; use Illuminate\Validation\Rules;
use Illuminate\Validation\Rule;
use Illuminate\View\View; use Illuminate\View\View;
class RegisteredUserController extends Controller class RegisteredUserController extends Controller
...@@ -33,19 +34,31 @@ public function store(Request $request): RedirectResponse ...@@ -33,19 +34,31 @@ public function store(Request $request): RedirectResponse
$request->validate([ $request->validate([
'name' => ['required', 'string', 'max:255'], 'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class], 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'role_id' => ['required', 'integer', Rule::exists('roles', 'id')],
'password' => ['required', 'confirmed', Rules\Password::defaults()], 'password' => ['required', 'confirmed', Rules\Password::defaults()],
'designation' => ['required', 'string', 'max:255'],
]); ]);
$user = User::create([ $user = User::create([
'name' => $request->name, 'name' => $request->name,
'email' => $request->email, 'email' => $request->email,
'role_id' => $request->role_id,
'password' => Hash::make($request->password), 'password' => Hash::make($request->password),
'designation' => $request->designation,
]); ]);
event(new Registered($user)); event(new Registered($user));
Auth::login($user); Auth::login($user);
return redirect(RouteServiceProvider::HOME); if(auth()->check() && auth()->user()->role->name === 'admin'){
return redirect(RouteServiceProvider::ADMINHOME);
}
else{
return redirect(RouteServiceProvider::USERHOME);
}
} }
} }
<?php
namespace App\Http\Controllers;
use App\Models\Project;
use App\Models\User;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
public function index()
{
$projects = Project::with('creator')->get();
$users = User::all();
return view('admin.projects', compact('projects', 'users'));
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'slug' => 'required|string|max:255|unique:projects',
'description' => 'required|string',
'start_date' => 'required|date',
'end_date' => 'required|date|after_or_equal:start_date',
'created_by' => 'required|exists:users,id',
]);
Project::create($validated);
return redirect()->route('admin.projects')->with('success', 'Project created successfully.');
}
}
...@@ -21,10 +21,14 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp ...@@ -21,10 +21,14 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp
foreach ($guards as $guard) { foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) { if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME); $user=Auth::user();
if($user->role->name==='admin'){
return redirect(RouteServiceProvider::ADMINHOME);
}else{
return redirect(RouteServiceProvider::USERHOME);
} }
} }
}
return $next($request); return $next($request);
} }
} }
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
use HasFactory;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
use HasFactory;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use HasFactory;
protected $fillable = ['name', 'slug', 'description', 'start_date', 'end_date', 'created_by'];
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $fillable = ['name'];
public function users()
{
return $this->hasMany(User::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Task extends Model
{
use HasFactory;
}
...@@ -21,6 +21,8 @@ class User extends Authenticatable ...@@ -21,6 +21,8 @@ class User extends Authenticatable
'name', 'name',
'email', 'email',
'password', 'password',
'role_id',
'designation',
]; ];
/** /**
...@@ -33,6 +35,14 @@ class User extends Authenticatable ...@@ -33,6 +35,14 @@ class User extends Authenticatable
'remember_token', 'remember_token',
]; ];
public function role()
{
return $this->belongsTo(Role::class);
}
public function projects()
{
return $this->hasMany(Project::class, 'created_by');
}
/** /**
* The attributes that should be cast. * The attributes that should be cast.
* *
......
...@@ -17,7 +17,9 @@ class RouteServiceProvider extends ServiceProvider ...@@ -17,7 +17,9 @@ class RouteServiceProvider extends ServiceProvider
* *
* @var string * @var string
*/ */
public const HOME = '/dashboard'; public const ADMINHOME = '/admin/dashboard';
public const USERHOME = '/user/dashboard';
/** /**
* Define your route model bindings, pattern filters, and other route configuration. * Define your route model bindings, pattern filters, and other route configuration.
......
...@@ -11,14 +11,9 @@ ...@@ -11,14 +11,9 @@
*/ */
public function up(): void public function up(): void
{ {
Schema::create('personal_access_tokens', function (Blueprint $table) { Schema::create('roles', function (Blueprint $table) {
$table->id(); $table->id();
$table->morphs('tokenable'); $table->string('name')->unique();
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }
...@@ -28,6 +23,6 @@ public function up(): void ...@@ -28,6 +23,6 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('personal_access_tokens'); Schema::dropIfExists('roles');
} }
}; };
...@@ -15,10 +15,10 @@ public function up(): void ...@@ -15,10 +15,10 @@ public function up(): void
$table->id(); $table->id();
$table->string('name'); $table->string('name');
$table->string('email')->unique(); $table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password'); $table->string('password');
$table->rememberToken(); $table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->timestamps(); $table->timestamps();
$table->softDeletes();
}); });
} }
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->dateTime('start_date');
$table->dateTime('end_date');
$table->foreignId('created_by')->constrained('users')->onDelete('cascade');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('projects');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->onDelete('cascade');
$table->string('title');
$table->text('description')->nullable();
$table->string('status');
$table->string('priority');
$table->dateTime('due_date');
$table->foreignId('created_by')->constrained('users')->onDelete('cascade');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tasks');
}
};
...@@ -11,14 +11,13 @@ ...@@ -11,14 +11,13 @@
*/ */
public function up(): void public function up(): void
{ {
Schema::create('failed_jobs', function (Blueprint $table) { Schema::create('files', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('uuid')->unique(); $table->foreignId('task_id')->constrained()->onDelete('cascade');
$table->text('connection'); $table->string('file_path');
$table->text('queue'); $table->string('original_name');
$table->longText('payload'); $table->foreignId('uploaded_by')->constrained('users')->onDelete('cascade');
$table->longText('exception'); $table->timestamps();
$table->timestamp('failed_at')->useCurrent();
}); });
} }
...@@ -27,6 +26,6 @@ public function up(): void ...@@ -27,6 +26,6 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('failed_jobs'); Schema::dropIfExists('files');
} }
}; };
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('task_id')->nullable()->constrained()->onDelete('set null');
$table->string('message');
$table->boolean('is_read')->default(false);
$table->timestamps();
$table->index('user_id');
$table->index('task_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('task_user', function (Blueprint $table) {
$table->id();
$table->foreignId('task_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('assigned_by')->constrained('users')->onDelete('cascade');
$table->timestamps();
$table->index(['task_id', 'user_id']);
$table->index('user_id');
$table->index('assigned_by');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('task_user');
}
};
...@@ -11,10 +11,8 @@ ...@@ -11,10 +11,8 @@
*/ */
public function up(): void public function up(): void
{ {
Schema::create('password_reset_tokens', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
$table->string('email')->primary(); $table->string('designation')->after('email');
$table->string('token');
$table->timestamp('created_at')->nullable();
}); });
} }
...@@ -23,6 +21,8 @@ public function up(): void ...@@ -23,6 +21,8 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('password_reset_tokens'); Schema::table('users', function (Blueprint $table) {
$table->dropColumn('designation');
});
} }
}; };
...@@ -12,11 +12,9 @@ class DatabaseSeeder extends Seeder ...@@ -12,11 +12,9 @@ class DatabaseSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
// \App\Models\User::factory(10)->create(); $this->call([
RoleSeeder::class,
// \App\Models\User::factory()->create([ UserSeeder::class,
// 'name' => 'Test User', ]);
// 'email' => 'test@example.com',
// ]);
} }
} }
<?php
namespace Database\Seeders;
use App\Models\Role;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Role::create(['name'=>'admin']);
Role::create(['name'=>'user']);
}
}
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
User::create([
'name' => 'admin',
'email' => 'admin@gmail.com',
'password' => Hash::make('admin@123'),
'role_id' => 1
]);
}
}
.admin-page {
padding: 60px 20px;
max-width: 1200px;
margin: auto;
font-size: 18px;
}
.admin-actions {
margin-top: 20px;
}
a.user-button {
display: inline-block;
background-color: #4f46e5;
color: white;
padding: 12px 24px;
border-radius: 8px;
text-decoration: none;
transition: background-color 0.2s;
font-weight: 500;
}
a.user-button:hover {
background-color: #4338ca;
}
a.project-button {
display: inline-block;
background-color: #4f46e5;
color: white;
padding: 12px 24px;
border-radius: 8px;
text-decoration: none;
transition: background-color 0.2s;
font-weight: 500;
}
a.project-button:hover {
background-color: #4338ca;
}
\ No newline at end of file
.users-container {
max-width: 1200px;
margin: 40px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
text-align: center;
}
h1{
font-size: 30px;
}
.action-bar {
margin-bottom: 20px;
text-align: right;
}
.create-button {
background-color: #28a745;
color: black;
padding: 10px 16px;
border: none;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
}
.form-section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #ccc;
background-color: #ffffff;
border-radius: 8px;
}
.hidden {
display: none;
}
.form-grid {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.form-group {
flex: 1 1 45%;
display: flex;
flex-direction: column;
}
.form-group.full-width {
flex: 1 1 100%;
}
.form-group label {
margin-bottom: 6px;
font-weight: bold;
}
.form-group input,
.form-group select {
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
.submit-button {
margin-top: 20px;
background-color: #007bff;
color: black;
padding: 10px 16px;
border: none;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
}
.user-table {
width: 100%;
border-collapse: collapse;
margin-top: 30px;
}
.user-table th,
.user-table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
.user-table th {
background-color: #f0f0f0;
font-weight: bold;
}
.projects-container {
max-width: 1000px;
margin: 2rem auto;
padding: 1rem 2rem;
font-family: Arial, sans-serif;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgb(0 0 0 / 0.1);
}
h1 {
font-size: 1.8rem;
margin-bottom: 1rem;
color: #333;
}
.action-bar {
margin-bottom: 1rem;
display: flex;
justify-content: flex-start;
}
.create-button {
background-color: #2563eb; /* Blue */
color: white;
font-weight: 600;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.create-button:hover {
background-color: #1e40af;
}
.form-section {
margin-bottom: 2rem;
border: 1px solid #ddd;
padding: 1rem;
border-radius: 6px;
background-color: #fafafa;
}
.hidden {
display: none;
}
.form-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1rem 2rem;
align-items: center;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
font-weight: 600;
margin-bottom: 0.4rem;
color: #555;
}
.form-group input,
.form-group textarea,
.form-group select {
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
transition: border-color 0.2s ease;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
border-color: #2563eb;
outline: none;
box-shadow: 0 0 0 2px rgb(37 99 235 / 0.3);
}
.form-group.full-width {
grid-column: 1 / -1;
}
.submit-button {
background-color: #10b981; /* Green */
color: white;
font-weight: 700;
border: none;
padding: 0.6rem 1.5rem;
border-radius: 4px;
cursor: pointer;
margin-top: 1rem;
transition: background-color 0.3s ease;
}
.submit-button:hover {
background-color: #047857;
}
.project-table {
width: 100%;
border-collapse: collapse;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}
.project-table thead {
background-color: #f3f4f6;
border-bottom: 2px solid #e5e7eb;
}
.project-table th,
.project-table td {
text-align: left;
padding: 0.75rem 1rem;
border-bottom: 1px solid #e5e7eb;
color: #374151;
font-size: 0.95rem;
}
.project-table tbody tr:hover {
background-color: #f9fafb;
cursor: default;
}
<x-app-layout>
<x-slot name="header">Welcome Admin</x-slot>
<div class="admin-page">
<div class="admin-actions">
<a href="{{ route('admin.users') }}" class="user-button">
List All Users
</a>
<a href="{{ route('admin.projects') }}" class="project-button">
Create New Project
</a>
</div>
</div>
</x-app-layout>
<x-app-layout>
<x-slot name="header">Project Management Page</x-slot>
<div class="projects-container">
<h1>Project List</h1>
<div class="action-bar">
<button onclick="document.getElementById('createForm').classList.toggle('hidden')" class="create-button">
+ Create New Project
</button>
</div>
<div id="createForm" class="form-section hidden">
<form action="{{ route('admin.projects.store') }}" method="POST">
@csrf
<div class="form-grid">
<div class="form-group">
<label>Name</label>
<input type="text" name="name" required>
</div>
<div class="form-group">
<label>Slug</label>
<input type="text" name="slug" required>
</div>
<div class="form-group full-width">
<label>Description</label>
<textarea name="description" rows="3" required></textarea>
</div>
<div class="form-group">
<label>Start Date</label>
<input type="datetime-local" name="start_date" required>
</div>
<div class="form-group">
<label>End Date</label>
<input type="datetime-local" name="end_date" required>
</div>
<div class="form-group">
<label>Created By</label>
<select name="created_by" required>
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->name }}</option>
@endforeach
</select>
</div>
</div>
<button type="submit" class="submit-button">Create Project</button>
</form>
</div>
<table class="project-table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Slug</th>
<th>Description</th>
<th>Start Date</th>
<th>End Date</th>
<th>Created By</th>
</tr>
</thead>
<tbody>
@foreach ($projects as $project)
<tr>
<td>{{ $project->id }}</td>
<td>{{ $project->name }}</td>
<td>{{ $project->slug }}</td>
<td>{{ Str::limit($project->description, 50) }}</td>
<td>{{ $project->start_date }}</td>
<td>{{ $project->end_date }}</td>
<td>{{ $project->creator->name }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</x-app-layout>
<x-app-layout>
<x-slot name="header">User Management Page</x-slot>
<div class="users-container">
<h1>User List</h1>
<div class="action-bar">
<button onclick="document.getElementById('createForm').classList.toggle('hidden')" class="create-button">
+ Create New User
</button>
</div>
<div id="createForm" class="form-section hidden">
<form action="{{ route('admin.users.store') }}" method="POST">
@csrf
<div class="form-grid">
<div class="form-group">
<label>Name</label>
<input type="text" name="name" required>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" required>
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" name="designation">
</div>
<div class="form-group full-width">
<label>Role</label>
<select name="role_id">
@foreach($roles as $role)
<option value="{{ $role->id }}">{{ $role->name }}</option>
@endforeach
</select>
</div>
</div>
<button type="submit" class="submit-button">Create User</button>
</form>
</div>
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Designation</th>
<th>Role</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->designation }}</td>
<td>{{ $user->role->name }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</x-app-layout>
...@@ -32,6 +32,14 @@ ...@@ -32,6 +32,14 @@
</label> </label>
</div> </div>
<div class="flex items-center justify-start mt-4">
<span class="text-sm text-gray-600 dark:text-gray-400">Not registered?</span>
<a href="{{ route('register') }}" class="ml-2 underline text-sm text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-200">
Register here
</a>
</div>
<div class="flex items-center justify-end mt-4"> <div class="flex items-center justify-end mt-4">
@if (Route::has('password.request')) @if (Route::has('password.request'))
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}"> <a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}">
......
...@@ -39,6 +39,17 @@ ...@@ -39,6 +39,17 @@
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" /> <x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
</div> </div>
<div>
<label for="designation">Designation</label>
<input id="designation" name="designation" type="text" required class="mt-1 block w-full" />
</div>
<select name="role_id">
<option value="1">Admin</option>
<option value="2">User</option>
</select>
<div class="flex items-center justify-end mt-4"> <div class="flex items-center justify-end mt-4">
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('login') }}"> <a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('login') }}">
{{ __('Already registered?') }} {{ __('Already registered?') }}
......
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Dashboard') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __("You're logged in!") }}
</div>
</div>
</div>
</div>
</x-app-layout>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" /> <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
<!-- Scripts --> <!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js']) @vite(['resources/css/app.css', 'resources/js/app.js','resources/css/admindash.css','resources/css/listuser.css','resources/css/projectlist.css'])
</head> </head>
<body class="font-sans antialiased"> <body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100 dark:bg-gray-900"> <div class="min-h-screen bg-gray-100 dark:bg-gray-900">
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
<div class="flex"> <div class="flex">
<!-- Logo --> <!-- Logo -->
<div class="shrink-0 flex items-center"> <div class="shrink-0 flex items-center">
<a href="{{ route('dashboard') }}"> <a href="{{ route('login') }}">
<x-application-logo class="block h-9 w-auto fill-current text-gray-800 dark:text-gray-200" /> <x-application-logo class="block h-9 w-auto fill-current text-gray-800 dark:text-gray-200" />
</a> </a>
</div> </div>
<!-- Navigation Links --> <!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex"> <div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> <x-nav-link :href="route('login')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }} {{ __('Dashboard') }}
</x-nav-link> </x-nav-link>
</div> </div>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<!-- Responsive Navigation Menu --> <!-- Responsive Navigation Menu -->
<div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden"> <div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden">
<div class="pt-2 pb-3 space-y-1"> <div class="pt-2 pb-3 space-y-1">
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> <x-responsive-nav-link :href="route('login')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }} {{ __('Dashboard') }}
</x-responsive-nav-link> </x-responsive-nav-link>
</div> </div>
......
<x-app-layout>
<x-slot name="header">Welcome User</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto">You are logged in as <strong>User</strong>.</div>
</div>
</x-app-layout>
<?php <?php
use App\Http\Controllers\AdminUserController;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\ProjectController;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Web Routes | Web Routes
...@@ -15,17 +16,39 @@ ...@@ -15,17 +16,39 @@
*/ */
Route::get('/', function () { Route::get('/', function () {
return view('welcome'); if(Auth::check()){
return Auth::user()->role->name==='admin'
? redirect()->route('admin.dashboard')
: redirect()->route('user.dashboard');
}
return redirect()->route('login');
}); });
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
Route::get('/user/dashboard', function() {
return view('user.dashboard');
})->name('user.dashboard');
});
Route::middleware('auth')->prefix('admin')->group(function () {
Route::get('/dashboard', function() {
if(Auth::user()->role->name !== 'admin') {
return redirect()->route('user.dashboard');
}
return view('admin.dashboard');
})->name('admin.dashboard');
Route::get('/users', [AdminUserController::class, 'index'])->name('admin.users');
Route::post('/users', [AdminUserController::class, 'store'])->name('admin.users.store');
Route::get('projects', [ProjectController::class, 'index'])->name('admin.projects');
Route::post('projects', [ProjectController::class, 'store'])->name('admin.projects.store');
}); });
require __DIR__.'/auth.php'; require __DIR__.'/auth.php';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment