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

08 the end #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
104 changes: 104 additions & 0 deletions app/Http/Controllers/Api/EmployeeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\EmployeeRequest;
use App\Http\Resources\EmployeeResource;
use App\Http\Resources\EmployeeSingleResource;
use App\Models\Employee;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Response;

class EmployeeController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
* @return AnonymousResourceCollection
*/
public function index(Request $request)
{
$employees = Employee::all();
if ($request->search) {
$employees = Employee::where('first_name', 'like', "%{$request->search}%")
->orWhere('last_name', 'like', "%{$request->search}%")->get();
} elseif ($request->department_id && $request->department_id !== 'selected') {
$employees = Employee::where('department_id', 'like', "%{$request->department_id}%")
->get();
}
return EmployeeResource::collection($employees);
}

/**
* Show the form for creating a new resource.
*
* @return void
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param EmployeeRequest $request
* @return JsonResponse
*/
public function store(EmployeeRequest $request)
{
$employee = Employee::create($request->validated());

return response()->json($employee);
}

/**
* Display the specified resource.
*
* @param Employee $employee
* @return EmployeeSingleResource
*/
public function show(Employee $employee)
{
return new EmployeeSingleResource($employee);
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return void
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param EmployeeRequest $request
* @param Employee $employee
* @return void
*/
public function update(EmployeeRequest $request, Employee $employee)
{
$employee->update($request->validated());
}

/**
* Remove the specified resource from storage.
*
* @param Employee $employee
* @return JsonResponse
*/
public function destroy(Employee $employee)
{
$employee->delete();
return response()->json('Employee Delete Successfully');
}
}
36 changes: 36 additions & 0 deletions app/Http/Controllers/Api/EmployeeDataController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Country;
use App\Models\Department;
use App\Models\State;
use Illuminate\Http\Request;

class EmployeeDataController extends Controller
{
public function countries()
{
$countries = Country::all();
return response()->json($countries);
}

public function states(Country $country)
{
return response()->json($country->states);
}

public function departments()
{
$departments = Department::all();
return response()->json($departments);

}

public function cities(State $state)
{
return response()->json($state->cities);

}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class LoginController extends Controller
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;

protected $maxAttempts = 3; //default 5
protected $decayMinutes = 5; //default 1
/**
* Create a new controller instance.
*
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string', 'max:255','unique:users'],
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
Expand All @@ -65,7 +67,9 @@ protected function validator(array $data)
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/Backend/ChangePasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class ChangePasswordController extends Controller
{
public function change_password(Request $request, User $user)
{
$request->validate([
'password' => ['required', 'string', 'confirmed'],
]);

$user->update([
'password' => Hash::make($request->password)
]);
return redirect()->route('users.index')->with('message', 'User Password Updated Successfully');

}
}
96 changes: 96 additions & 0 deletions app/Http/Controllers/Backend/CityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Http\Requests\CityRequest;

use App\Models\City;

use App\Models\State;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class CityController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
* @return Factory|View
*/
public function index(Request $request)
{
$cities = City::all();
if ($request->has('search')) {
$cities = City::where('name', 'like', "%{$request->search}%")->get();
}
return view('cities.index', compact('cities'));
}

/**
* Show the form for creating a new resource.
*
* @return Factory|View
*/
public function create()
{
$states = State::all();
return view('cities.create', compact('states'));
}

/**
* Store a newly created resource in storage.
*
* @param CityRequest $request
* @return RedirectResponse
*/
public function store(CityRequest $request)
{
City::create($request->validated());

return redirect()->route('cities.index')->with('message', 'City Create Successfully');

}


/**
* Show the form for editing the specified resource.
*
* @param City $city
* @return Factory|View
*/
public function edit(City $city)
{
$states = State::all();
return view('cities.edit', compact('city','states'));
}

/**
* Update the specified resource in storage.
*
* @param CityRequest $request
* @param City $city
* @return RedirectResponse
*/
public function update(CityRequest $request, City $city)
{
$city->update($request->validated());

return redirect()->route('cities.index')->with('message', 'City Update Successfully');
}

/**
* Remove the specified resource from storage.
*
* @param City $city
* @return RedirectResponse
*/
public function destroy(City $city)
{
$city->delete();
return redirect()->route('cities.index')->with('message', 'State Delete Successfully');
}
}
96 changes: 96 additions & 0 deletions app/Http/Controllers/Backend/CountryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Http\Requests\CountryStoreRequest;
use App\Models\Country;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CountryController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
* @return Factory|View
*/
public function index(Request $request)
{
/*$countries = Country::all();
if ($request->has('search')){
$countries = Country::where('name','like',"%{$request->search}%")->orWhere('country_code','like',"%{$request->search}%")->get();
}*/
$search = request('search');
$countries = Country::when($search, function ($query, $search) {
$query->where('country_code', 'like', "%{$search}%")->orWhere('name','like',"%{$search}%");
})->paginate(2)->withQueryString();

return view('countries.index', compact('countries'));
}

/**
* Show the form for creating a new resource.
*
* @return Factory|View
*/
public function create()
{
return view('countries.create');
}

/**
* Store a newly created resource in storage.
*
* @param CountryStoreRequest $request
* @return RedirectResponse
*/
public function store(CountryStoreRequest $request)
{
Country::create($request->validated());

return redirect()->route('countries.index')->with('message', 'Country Create Successfully');

}

/**
* Show the form for editing the specified resource.
*
* @param Country $country
* @return Factory|View
*/
public function edit(Country $country)
{
return view('countries.edit', compact('country'));
}

/**
* Update the specified resource in storage.
*
* @param CountryStoreRequest $request
* @param Country $country
* @return RedirectResponse
*/
public function update(CountryStoreRequest $request, Country $country)
{
$country->update($request->validated());

return redirect()->route('countries.index')->with('message', 'Country Update Successfully');
}

/**
* Remove the specified resource from storage.
*
* @param Country $country
* @return RedirectResponse
*/
public function destroy(Country $country)
{
$country->delete();
return redirect()->route('countries.index')->with('message', 'Country Delete Successfully');
}
}
Loading