40 lines
817 B
PHP
40 lines
817 B
PHP
<?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();
|
|
}
|
|
}
|