StocksNew/Modules/User/app/Repositories/UserRepository.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

41 lines
859 B
PHP

<?php
namespace Modules\User\Repositories;
use App\Models\User;
class UserRepository implements UserInterface
{
public function findAll()
{
return User::with(['employee.department'])->get();
}
public function getUserById($userId)
{
return User::findOrFail($userId);
}
public function create(array $userDetails, array $role)
{
$user = User::create($userDetails);
$user->roles()->attach($role);
return $user;
}
public function update($userId, array $newDetails, array $role)
{
$user = User::whereId($userId)->update($newDetails);
$user->roles()->sync($role);
return $user;
}
public function delete($userId)
{
$user = User::whereId($userId)->first();
$user->roles()->detach();
return $user->destroy();
}
}