master_template/app/Repositories/UserRepository.php

40 lines
817 B
PHP
Raw Normal View History

2024-06-23 11:17:56 +00:00
<?php
namespace App\Repositories;
use App\Models\User;
class UserRepository implements UserInterface
{
public function findAll()
{
return User::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->delete();
}
}