update
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface AdCategoriesInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Adcategories;
|
||||
use App\Repositories\Interface\AdCategoriesInterface;
|
||||
use App\Repositories\AdCategoriesInterface;
|
||||
|
||||
|
||||
class AdCategoryRepository implements AdCategoriesInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface AdvertisementInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Advertisements;
|
||||
use App\Repositories\Interface\AdvertisementInterface;
|
||||
use App\Repositories\AdvertisementInterface;
|
||||
|
||||
|
||||
class AdvertisementRepository implements AdvertisementInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface ArticleInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Articles;
|
||||
use App\Repositories\Interface\ArticleInterface;
|
||||
use App\Repositories\ArticleInterface;
|
||||
|
||||
|
||||
class ArticleRepository implements ArticleInterface
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Repositories\Interface\AuthorsInterface;
|
||||
use App\Repositories\AuthorsInterface;
|
||||
use App\Models\Authors;
|
||||
|
||||
class AuthorRepository implements AuthorsInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface AuthorsInterface
|
||||
{
|
9
app/Repositories/CommentsInterface.php
Normal file
9
app/Repositories/CommentsInterface.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
interface CommentsInterface{
|
||||
public function create(array $Details);
|
||||
public function update($commentId, array $newDetails);
|
||||
public function delete($commentId);
|
||||
}
|
25
app/Repositories/CommentsRepository.php
Normal file
25
app/Repositories/CommentsRepository.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Comments;
|
||||
use App\Repositories\CommentsInterface;
|
||||
|
||||
class CommentsRepository implements CommentsInterface
|
||||
{
|
||||
public function create(array $Details)
|
||||
{
|
||||
// dd($Details);
|
||||
return Comments::create($Details);
|
||||
}
|
||||
|
||||
public function update($commentId, array $Details)
|
||||
{
|
||||
return Comments::where('id', $commentId)->update($Details);
|
||||
}
|
||||
|
||||
public function delete($commentId)
|
||||
{
|
||||
return Comments::where('id', $commentId)->delete();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface EconomyInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Economies;
|
||||
use App\Repositories\Interface\EconomyInterface;
|
||||
use App\Repositories\EconomyInterface;
|
||||
|
||||
|
||||
class EconomyRepository implements EconomyInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface HoroscopeInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Horoscopes;
|
||||
use App\Repositories\Interface\HoroscopeInterface;
|
||||
use App\Repositories\HoroscopeInterface;
|
||||
|
||||
|
||||
class HoroscopeRepository implements HoroscopeInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface NewsCategoriesInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Newscategories;
|
||||
use App\Repositories\Interface\NewsCategoriesInterface;
|
||||
use App\Repositories\NewsCategoriesInterface;
|
||||
|
||||
class NewsCategoriesRepository implements NewsCategoriesInterface
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface NewsInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\News;
|
||||
use App\Repositories\Interface\NewsInterface;
|
||||
use App\Repositories\NewsInterface;
|
||||
|
||||
class NewsRepository implements NewsInterface
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface NewsTypeInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\News_type;
|
||||
use App\Repositories\Interface\NewsTypeInterface;
|
||||
use App\Repositories\NewsTypeInterface;
|
||||
|
||||
|
||||
class NewsTypeRepository implements NewsTypeInterface
|
||||
|
15
app/Repositories/PermissionInterface.php
Normal file
15
app/Repositories/PermissionInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
interface PermissionInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getPermissionById($permissionId);
|
||||
public function delete($permissionId);
|
||||
public function create(array $permissionDetails);
|
||||
public function update($permissionId, array $newDetails);
|
||||
public function getRoleById($roleId);
|
||||
public function getPermissionListsArrangedByPrefix();
|
||||
public static function generatePermissionFromRoutes();
|
||||
}
|
121
app/Repositories/PermissionRepository.php
Normal file
121
app/Repositories/PermissionRepository.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Repositories\PermissionInterface;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class PermissionRepository implements PermissionInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return Permission::get();
|
||||
}
|
||||
|
||||
public function getPermissionById($permissionId)
|
||||
{
|
||||
return Permission::findOrFail($permissionId);
|
||||
}
|
||||
|
||||
public function delete($permissionId)
|
||||
{
|
||||
Permission::destroy($permissionId);
|
||||
}
|
||||
|
||||
public function create(array $permissionDetails)
|
||||
{
|
||||
return Permission::create($permissionDetails);
|
||||
}
|
||||
|
||||
public function getRoleById($roleId)
|
||||
{
|
||||
return Role::with('permissions')->findOrFail($roleId);
|
||||
}
|
||||
|
||||
public function update($permissionId, array $newDetails)
|
||||
{
|
||||
return Permission::where('id', $permissionId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function getPermissionListsArrangedByPrefix()
|
||||
{
|
||||
$permissions = self::findAll();
|
||||
|
||||
$routeNameArr = [];
|
||||
foreach ($permissions as $permission) {
|
||||
if (!is_null($permission->name)) {
|
||||
$routeName = explode('.', $permission->name);
|
||||
if (is_array($routeName) && !empty($routeName[0])) {
|
||||
$routeNameArr[$routeName[0]][$permission->id] = array_key_exists(1, $routeName) ? $routeName[1] : $routeName[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $routeNameArr;
|
||||
}
|
||||
|
||||
public static function generatePermissionFromRoutes()
|
||||
{
|
||||
$routes = Route::getRoutes();
|
||||
// dd($routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
|
||||
$routeName = $route->getName();
|
||||
|
||||
$ignoreRoutes = [
|
||||
'installer',
|
||||
'LaravelUpdater',
|
||||
'debugbar',
|
||||
'login',
|
||||
'register',
|
||||
'logout',
|
||||
'post',
|
||||
'ignition',
|
||||
'unisharp',
|
||||
'userLogin',
|
||||
'postLogin',
|
||||
'postLogin',
|
||||
'postresgistration',
|
||||
'home',
|
||||
'single',
|
||||
'newsDetail',
|
||||
'password',
|
||||
'showHororscope',
|
||||
'showInternational',
|
||||
'showVideos',
|
||||
'videoDetail',
|
||||
'showAboutus',
|
||||
'showArtilce',
|
||||
'showProvinces',
|
||||
'contact',
|
||||
'sendEmail',
|
||||
'verification',
|
||||
'auth',
|
||||
'upload',
|
||||
'sanctum',
|
||||
'ignition',
|
||||
'welcome',
|
||||
'home',
|
||||
'api'
|
||||
];
|
||||
|
||||
$routePrefix = explode('.', $routeName);
|
||||
|
||||
if (is_array($routePrefix) && !empty($routePrefix[0])) {
|
||||
if (!in_array($routePrefix[0], $ignoreRoutes) && !Permission::where('name', $routeName)->exists()) {
|
||||
Permission::create(['name' => $routeName, 'guard_name' => 'web']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$roles = Role::all();
|
||||
foreach ($roles as $role) {
|
||||
|
||||
if ($role->name == 'admin' || $role->name == 'editor') {
|
||||
$role->givePermissionTo(Permission::all());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface PopupInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Popups;
|
||||
use App\Repositories\Interface\PopupInterface;
|
||||
use App\Repositories\PopupInterface;
|
||||
|
||||
class PopupRepository implements PopupInterface
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface ProvinceInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Provinces;
|
||||
use App\Repositories\Interface\ProvinceInterface;
|
||||
use App\Repositories\ProvinceInterface;
|
||||
|
||||
|
||||
class ProvinceRepository implements ProvinceInterface
|
||||
|
13
app/Repositories/RoleInterface.php
Normal file
13
app/Repositories/RoleInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
interface RoleInterface
|
||||
{
|
||||
public function pluck();
|
||||
public function findAll();
|
||||
public function getRoleById($roleId);
|
||||
public function delete($roleId);
|
||||
public function create(array $RoleDetails);
|
||||
public function update($roleId, array $newDetails);
|
||||
}
|
57
app/Repositories/RoleRepository.php
Normal file
57
app/Repositories/RoleRepository.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RoleRepository implements RoleInterface
|
||||
{
|
||||
public function pluck()
|
||||
{
|
||||
return Role::pluck('name', 'id');
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return Role::with('permissions')->get();
|
||||
}
|
||||
|
||||
public function getRoleById($roleId)
|
||||
{
|
||||
return Role::with('permissions')->findOrFail($roleId);
|
||||
}
|
||||
|
||||
public function delete($roleId)
|
||||
{
|
||||
$role = self::getRoleById($roleId);
|
||||
$role->permissions()->detach();
|
||||
return $role->delete();
|
||||
}
|
||||
|
||||
public function create(array $roleDetails)
|
||||
{
|
||||
return Role::create($roleDetails);
|
||||
}
|
||||
|
||||
public function update($roleId, array $newDetails)
|
||||
{
|
||||
$role = Role::find($roleId);
|
||||
$role->update($newDetails);
|
||||
return $role;
|
||||
}
|
||||
public function getPermissionListsArrangedByPrefix()
|
||||
{
|
||||
$permissions = self::findAll();
|
||||
|
||||
$routeNameArr = [];
|
||||
foreach ($permissions as $permission) {
|
||||
if (!is_null($permission->name)) {
|
||||
$routeName = explode('.', $permission->name);
|
||||
if (is_array($routeName) && !empty($routeName[0])) {
|
||||
$routeNameArr[$routeName[0]][$permission->id] = array_key_exists(1, $routeName) ? $routeName[1] : $routeName[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $routeNameArr;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface SettingInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Settings;
|
||||
use App\Repositories\Interface\SettingInterface;
|
||||
use App\Repositories\SettingInterface;
|
||||
|
||||
class SettingRepository implements SettingInterface
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface TeamsInterface
|
||||
{
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Teams;
|
||||
use App\Repositories\Interface\TeamsInterface;
|
||||
use App\Repositories\TeamsInterface;
|
||||
|
||||
class TeamsRepository implements TeamsInterface
|
||||
{
|
||||
|
12
app/Repositories/UserInterface.php
Normal file
12
app/Repositories/UserInterface.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
interface UserInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getUserById($userId);
|
||||
public function delete($userId);
|
||||
public function create(array $UserDetails, array $role);
|
||||
public function update($userId, array $newDetails, array $role);
|
||||
}
|
39
app/Repositories/UserRepository.php
Normal file
39
app/Repositories/UserRepository.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Videos;
|
||||
use App\Repositories\Interface\VideosInterface;
|
||||
use App\Repositories\VideosInterface;
|
||||
|
||||
|
||||
class VideoRepository implements VideosInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Interface;
|
||||
namespace App\Repositories;
|
||||
|
||||
interface VideosInterface
|
||||
{
|
Reference in New Issue
Block a user