Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Main #27

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Also, you will need to install Composer: https://getcomposer.org/doc/00-intro.md

## Usage

Register a user or login using admin@volt.com and secret and start testing the Laravel app (make sure to run the migrations and seeders for these credentials to be available).
Register a user or login using admin@gmail.com and secret and start testing the Laravel app (make sure to run the migrations and seeders for these credentials to be available).
Make sure to run the migrations and seeders for the above credentials to be available.

Make sure to run the migrations and seeders for the above credentials to be available.
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/AcademicController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AcademicController extends Controller
{
//
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminController extends Controller
{
public function index()
{
return view('livewire.admin');
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/StudentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class StudentController extends Controller
{
public function index()
{
return view('livewire.user');
}
}
4 changes: 4 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

'admin' => \App\Http\Middleware\Admin::class,
'student' => \App\Http\Middleware\Student::class,
'academic' => \App\Http\Middleware\Academic::class,
];
}
23 changes: 19 additions & 4 deletions app/Http/Livewire/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,53 @@

use App\Models\User;
use Livewire\Component;
use Auth;

class Login extends Component
{

public $email = '';
public $password = '';
public $remember_me = false;
public $redirectTo; // Change this line to public

protected $rules = [
'email' => 'required|email:rfc,dns',
'password' => 'required|min:6',
];

//This mounts the default credentials for the admin. Remove this section if you want to make it public.
public function mount()
{
if (auth()->user()) {
return redirect()->intended('/dashboard');
}
$this->fill([
'email' => 'admin@volt.com',
'email' => 'admin@gmail.com',
'password' => 'secret',
]);
}

public function redirectTo()
{
switch (Auth::user()->role) {
case 1:
$this->redirectTo = '/admin';
return $this->redirectTo;
case 2:
$this->redirectTo = '/user';
return $this->redirectTo;
default:
$this->redirectTo = '/dashboard'; //if user doesn't have any role
return $this->redirectTo;
}
}

public function login()
{
$credentials = $this->validate();
if (auth()->attempt(['email' => $this->email, 'password' => $this->password], $this->remember_me)) {
$user = User::where(['email' => $this->email])->first();
auth()->login($user, $this->remember_me);
return redirect()->intended('/dashboard');
return redirect()->intended($this->redirectTo()); // Update this line to use redirectTo method
} else {
return $this->addError('email', trans('auth.failed'));
}
Expand Down
27 changes: 21 additions & 6 deletions app/Http/Livewire/Auth/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

class Register extends Component
{

public $email = '';
public $password = '';
public $passwordConfirmation = '';
public $role;

public function mount()
{
Expand All @@ -23,25 +23,40 @@ public function mount()

public function updatedEmail()
{
$this->validate(['email'=>'required|email:rfc,dns|unique:users']);
$this->validate(['email' => 'required|email:rfc,dns|unique:users']);
}

public function register()
{
$this->validate([
'email' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required|same:passwordConfirmation|min:6',
'role' => 'required|integer|in:1,2,3',
]);

$user = User::create([
'email' =>$this->email,
'email' => $this->email,
'password' => Hash::make($this->password),
'remember_token' => Str::random(10),
'role' => $this->role,
]);

auth()->login($user);

return redirect('/profile');
// Redirect based on role
return $this->redirectBasedOnRole($user->role);
}

protected function redirectBasedOnRole($role)
{
switch ($role) {
case 1:
return redirect('/admin'); // Redirect to admin dashboard
case 2:
return redirect('/user');
default:
return redirect('/dashboard'); // Default fallback
}
}

public function render()
Expand Down
35 changes: 34 additions & 1 deletion app/Http/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,44 @@
namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Report;
use Illuminate\Support\Facades\Auth;

class Dashboard extends Component
{
use WithPagination; // Add pagination trait for Livewire

public $search = ''; // Initialize search as an empty string
public $confirmingDelete = false;
public $user;

public function render()
{
return view('dashboard');
// Get the authenticated user
$this->user = Auth::user();

// Query for reports, applying search filter if present
$query = Report::query();

// Apply search filter
if (!empty($this->search)) {
$query->where('item_name', 'like', '%' . $this->search . '%');
}

// Get paginated results
$reports = $query->paginate(10);

// Return view with data
return view('livewire.dashboard', [
'user' => $this->user,
'reports' => $reports
]);
}

public function updatingSearch()
{
// Reset pagination when the search term is updated
$this->resetPage();
}
}
57 changes: 57 additions & 0 deletions app/Http/Livewire/EditReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Report;

class EditReport extends Component
{
public $item_name, $item_code, $generic_item_name, $item_category, $department, $machine, $test_code, $test_name;
public $supplier_name, $address, $manufacture, $hsn_code, $unit_of_perchase, $pack_size, $test, $unit_price, $cgst, $sgst, $price_gst;
public $reportId, $deleteId; // For storing the current report ID for editing

public function mount($id)
{
if ($id) {
$this->edit($id); // Load the report details for editing
}
}

public function edit($id)
{
$report = Report::find($id);

if ($report) {
$this->reportId = $report->id;
$this->item_name = $report->item_name;
$this->item_code = $report->item_code;
$this->generic_item_name = $report->generic_item_name;
$this->item_category = $report->item_category;
$this->department = $report->department;
$this->machine = $report->machine;
$this->test_code = $report->test_code;
$this->test_name = $report->test_name;
$this->supplier_name = $report->supplier_name;
$this->address = $report->address;
$this->manufacture = $report->manufacture;
$this->hsn_code = $report->hsn_code;
$this->unit_of_perchase = $report->unit_of_perchase;
$this->pack_size = $report->pack_size;
$this->test = $report->test;
$this->unit_price = $report->unit_price;
$this->cgst = $report->cgst;
$this->sgst = $report->sgst;
$this->price_gst = $report->price_gst;
return $this->render();
} else {
// Handle case when the report is not found
session()->flash('error', 'Report not found.');
}
}

public function render()
{
return view('livewire.edit-report');
}
}
Loading