update
This commit is contained in:
34
app/Console/Commands/GeneratePermissions.php
Normal file
34
app/Console/Commands/GeneratePermissions.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Repositories\PermissionRepository;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class GeneratePermissions extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'permissions:generate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate Permissions From Named Route';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->info('Generating Permissions');
|
||||
PermissionRepository::generatePermissionFromRoutes();
|
||||
$this->info('Permissions generated successfully!');
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ class Kernel extends ConsoleKernel
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
// $this->load(__DIR__.'/Commands/GeneratePermissions.php');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
@ -33,23 +33,213 @@ class CCMS
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
// private function initDB()
|
||||
// {
|
||||
// static $initialized = false;
|
||||
// if (!$initialized) {
|
||||
|
||||
|
||||
// if (!(DB::table('users')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_users` (`name`,`email`,`username`,`password`,`status`) VALUES ('Prajwal Adhikari','prajwalbro@hotmail.com','prajwalbro@hotmail.com','$2y$10$3zlF9VeXexzWKRDPZuDio.W7RZIC3tU.cjwMoLzG8ki8bVwAQn1WW','1');");
|
||||
// }
|
||||
// if (!(DB::table('settings')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_settings` (`title`, `description`, `status`) values ('Bibhuti LMS', '', '1');");
|
||||
// }
|
||||
// if (!(DB::table('articles')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_articles` (`title`,`alias`, `text`, `status`) VALUES ('Company Profile', 'company-profile','Welcome Article', '1');");
|
||||
// }
|
||||
|
||||
// $initialized = true;
|
||||
function getRouteList()
|
||||
{
|
||||
$routes = Route::getRoutes();
|
||||
$ignoreRoutes = ['debugbar', 'login', 'register', 'logout', 'post', 'sanctum', 'ignition', 'unisharp', 'errorpage', 'form7', 'master', 'hr', 'setting', 'nepalidictonary', 'api'];
|
||||
$routeNameArr = [];
|
||||
foreach ($routes as $value) {
|
||||
if (!is_null($value)) {
|
||||
$routeName = explode('.', $value->getName());
|
||||
if (is_array($routeName) && !empty($routeName[0])) {
|
||||
if (!in_array($routeName[0], $ignoreRoutes)) {
|
||||
$routeNameArr[$routeName[0]][] = $value->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $routeNameArr;
|
||||
}
|
||||
|
||||
function generateEstimateNumber()
|
||||
{
|
||||
$lastEstimate = Estimate::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastEstimate) {
|
||||
$newEstimateNumber = intval($lastEstimate->id) + 1;
|
||||
return 'EST-' . activeFiscalYear('code') . '-' . str_pad($newEstimateNumber, 4, '0', STR_PAD_LEFT);
|
||||
|
||||
} else {
|
||||
return 'EST-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateCreditNoteNumber()
|
||||
{
|
||||
$lastCreditNote = CreditNote::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastCreditNote) {
|
||||
$newCreditNoteNumber = intval($lastCreditNote->id) + 1;
|
||||
return 'CN-' . activeFiscalYear('code') . '-' . str_pad($newCreditNoteNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CN-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateInvoiceNumber()
|
||||
{
|
||||
$lastInvoice = Invoice::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastInvoice) {
|
||||
$newInvoiceNumber = intval($lastInvoice->id) + 1;
|
||||
return 'INV-' . activeFiscalYear('code') . '-' . str_pad($newInvoiceNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'INV-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateReceivedInvoiceNumber()
|
||||
{
|
||||
$lastReceivedInvoice = ReceivedInvoice::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastReceivedInvoice) {
|
||||
$newReceivedInvoiceNumber = intval($lastReceivedInvoice->id) + 1;
|
||||
return 'RI-' . activeFiscalYear('code') . '-' . str_pad($newReceivedInvoiceNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'RI-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateCashReceivedNumber()
|
||||
{
|
||||
$lastCastReceived = CashReceived::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastCastReceived) {
|
||||
$newCastReceivedNumber = intval($lastCastReceived->id) + 1;
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad($newCastReceivedNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
function generateDebitNoteNumber()
|
||||
{
|
||||
$lastDebitNote = DebitNote::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastDebitNote) {
|
||||
$newDebitNoteNumber = intval($lastDebitNote->id) + 1;
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad($newDebitNoteNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (!function_exists('sendNotification')) {
|
||||
// function sendNotification($user, $notification = [])
|
||||
// {
|
||||
// \Notification::send($user, new SendNotification($notification));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
if (!function_exists('uploadImage')) {
|
||||
function uploadImage($file)
|
||||
{
|
||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||
$filePath = Storage::disk('public')->putFileAs('uploads', $file, $fileName);
|
||||
return $filePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('activeFiscalYear')) {
|
||||
function activeFiscalYear($select)
|
||||
{
|
||||
$fiscalYearModel = FiscalYear::whereStatus(11)->first();
|
||||
return $fiscalYearModel->$select ?? null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('setting')) {
|
||||
function setting($key = '')
|
||||
{
|
||||
// Cache::forget('setting');
|
||||
$setting = Cache::has('setting') ? Cache::get('setting') : Cache::rememberForever('setting', function () {
|
||||
return Setting::get()->mapWithKeys(function ($setting) {
|
||||
return [$setting->key => $setting->value];
|
||||
});;
|
||||
});
|
||||
return $setting->has($key) ? $setting[$key] : null;
|
||||
}
|
||||
}
|
||||
|
||||
function convertAmountInWords($amount): string
|
||||
{
|
||||
$units = [
|
||||
'kharab' => 100000000000,
|
||||
'arab' => 1000000000,
|
||||
'crore' => 10000000,
|
||||
'lakh' => 100000,
|
||||
'thousand' => 1000,
|
||||
'hundred' => 100,
|
||||
];
|
||||
|
||||
$words = [];
|
||||
|
||||
foreach ($units as $unit => $value) {
|
||||
if ($amount >= $value) {
|
||||
$count = floor($amount / $value);
|
||||
$remaining = $amount % $value;
|
||||
$words[] = convertCount($count) . ' ' . $unit;
|
||||
$amount = $remaining;
|
||||
}
|
||||
}
|
||||
|
||||
if ($amount > 0) {
|
||||
$words[] = convertCount($amount);
|
||||
}
|
||||
|
||||
return implode(' ', $words) . ' only /-';
|
||||
}
|
||||
|
||||
function convertCount($count)
|
||||
{
|
||||
$ones = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
|
||||
$teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
|
||||
$tens = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
|
||||
|
||||
$words = [];
|
||||
|
||||
if ($count >= 100) {
|
||||
$words[] = $ones[floor($count / 100)] . ' hundred';
|
||||
$count %= 100;
|
||||
if ($count > 0) {
|
||||
$words[] = 'and';
|
||||
}
|
||||
}
|
||||
|
||||
if ($count >= 20) {
|
||||
$tensPlace = $tens[floor($count / 10) - 2];
|
||||
$onesPlace = $count % 10;
|
||||
if ($onesPlace > 0) {
|
||||
$words[] = $tensPlace . '-' . $ones[$onesPlace];
|
||||
} else {
|
||||
$words[] = $tensPlace;
|
||||
}
|
||||
} elseif ($count >= 10) {
|
||||
$words[] = $teens[$count - 10];
|
||||
} elseif ($count > 0) {
|
||||
$words[] = $ones[$count];
|
||||
}
|
||||
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
function getAllKeys($data)
|
||||
{
|
||||
$keys = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
if (is_object($item)) {
|
||||
$item = (array) $item;
|
||||
}
|
||||
|
||||
if (is_array($item)) {
|
||||
$subKeys = getAllKeys($item);
|
||||
$keys = array_merge($keys, $subKeys);
|
||||
} else {
|
||||
$keys[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($keys);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class AuthenticationController extends Controller
|
||||
'phone' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
User::create([
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
@ -59,6 +59,7 @@ class AuthenticationController extends Controller
|
||||
'email_verified_at' => now()
|
||||
])->assignRole('user');
|
||||
|
||||
dd($user);
|
||||
return response()->json(['success' => true, 'message' => 'User created successfully!', 'redirect_url' => route('userLogin')]);
|
||||
}
|
||||
|
||||
|
171
app/Http/Controllers/CommentsController.php
Normal file
171
app/Http/Controllers/CommentsController.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Comments;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Service\CommonModelService;
|
||||
use App\Repositories\CommentsRepository;
|
||||
use Log;
|
||||
use Exception;
|
||||
|
||||
class CommentsController extends Controller
|
||||
{
|
||||
protected $modelService;
|
||||
protected $commentRepository;
|
||||
public function __construct(Comments $model, CommentsRepository $commentRepository)
|
||||
{
|
||||
$this->modelService = new CommonModelService($model);
|
||||
$this->commentRepository = $commentRepository;
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'index', ' Comments index');
|
||||
$data = Comments::where('status','<>',-1)->orderBy('created_at')->get();
|
||||
|
||||
return view("crud.generated.comments.index", compact('data'));
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'create', ' Comments create');
|
||||
$TableData = Comments::where('status','<>',-1)->orderBy('created_at')->get();
|
||||
return view("crud.generated.comments.create",compact('TableData'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'store', ' Comments store');
|
||||
$validator = Validator::make($request->all(), [
|
||||
//ADD REQUIRED FIELDS FOR VALIDATION
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors(),
|
||||
],500);
|
||||
}
|
||||
|
||||
$requestData=$request->all();
|
||||
array_walk_recursive($requestData, function (&$value) {
|
||||
$value = str_replace(env('APP_URL').'/', '', $value);
|
||||
});
|
||||
array_walk_recursive($requestData, function (&$value) {
|
||||
$value = str_replace(env('APP_URL'), '', $value);
|
||||
});
|
||||
$this->commentRepository->create($requestData);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Comments Created Successfully.'], 200);
|
||||
}
|
||||
return redirect()->route('comments.index')->with('success','The Comments created Successfully.');
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
$idOrder = $request->input('id_order');
|
||||
|
||||
foreach ($idOrder as $index => $id) {
|
||||
$companyArticle = Comments::find($id);
|
||||
$companyArticle->display_order = $index + 1;
|
||||
$companyArticle->save();
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200);
|
||||
}
|
||||
public function updatealias(Request $request)
|
||||
{
|
||||
|
||||
$articleId = $request->input('articleId');
|
||||
$newAlias = $request->input('newAlias');
|
||||
$companyArticle = Comments::find($articleId);
|
||||
if (!$companyArticle) {
|
||||
return response()->json(['status' => false, 'content' => 'Company article not found.'], 404);
|
||||
}
|
||||
$companyArticle->alias = $newAlias;
|
||||
$companyArticle->save();
|
||||
return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'show', ' Comments show');
|
||||
$data = Comments::findOrFail($id);
|
||||
|
||||
return view("crud.generated.comments.show", compact('data'));
|
||||
}
|
||||
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'edit', ' Comments edit');
|
||||
$TableData = Comments::where('status','<>',-1)->orderBy('created_at')->get();
|
||||
$data = Comments::findOrFail($id);
|
||||
if ($request->ajax()) {
|
||||
$html = view("crud.generated.comments.ajax.edit", compact('data'))->render();
|
||||
return response()->json(['status' => true, 'content' => $html], 200);
|
||||
}
|
||||
return view("crud.generated.comments.edit", compact('data','TableData'));
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'update', ' Comments update');
|
||||
$validator = Validator::make($request->all(), [
|
||||
//ADD VALIDATION FOR REQIRED FIELDS
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors(),
|
||||
],500);
|
||||
}
|
||||
$filterData=$request->except(['_method','_token']);
|
||||
array_walk_recursive($filterData, function (&$value) {
|
||||
$value = str_replace(env('APP_URL').'/', '', $value);
|
||||
});
|
||||
array_walk_recursive($filterData, function (&$value) {
|
||||
$value = str_replace(env('APP_URL'), '', $value);
|
||||
});
|
||||
$this->commentRepository->update($id, $filterData);
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Comments updated Successfully.'], 200);
|
||||
}
|
||||
// return redirect()->route('comments.index')->with('success','The Comments updated Successfully.');
|
||||
return redirect()->back()->with('success', 'The Comments updated successfully.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request,$id)
|
||||
{
|
||||
// dd($id);
|
||||
$this->commentRepository->delete($id);
|
||||
return response()->json(['status'=>true,'message'=>'The Comments Deleted Successfully.'],200);
|
||||
}
|
||||
public function toggle(Request $request,$id)
|
||||
{
|
||||
createActivityLog(CommentsController::class, 'destroy', ' Comments destroy');
|
||||
$data = Comments::findOrFail($id);
|
||||
$requestData=['status'=>($data->status==1)?0:1];
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$OperationNumber = getOperationNumber();
|
||||
$this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id);
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
createErrorLog(CommentsController::class, 'destroy', $e->getMessage());
|
||||
return response()->json(['status' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['status'=>true,'message'=>'The Comments Deleted Successfully.'],200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,148 +3,104 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\RoleRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Service\CommonModelService;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Log;
|
||||
use Exception;
|
||||
use App\Repositories\PermissionRepository;
|
||||
|
||||
|
||||
class PermissionsController extends Controller
|
||||
{
|
||||
protected $modelService;
|
||||
public function __construct(Permission $model)
|
||||
{
|
||||
$this->modelService = new CommonModelService($model);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'index', ' Permissions index');
|
||||
$data = Permission::get();
|
||||
private $permissionRepository;
|
||||
private $role;
|
||||
|
||||
return view("crud.generated.permissions.index", compact('data'));
|
||||
public function __construct(permissionRepository $permissionRepository,
|
||||
RoleRepository $role)
|
||||
{
|
||||
$this->permissionRepository = $permissionRepository;
|
||||
$this->role = $role;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Permission Lists';
|
||||
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
||||
$data['roles'] = $this->role->pluck();
|
||||
$data['editable'] = false;
|
||||
return view('crud.generated.permissions.index', $data);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'create', ' Permissions create');
|
||||
$TableData = Permission::get();
|
||||
return view("crud.generated.permissions.create", compact('TableData'));
|
||||
$data['editable'] = false;
|
||||
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
||||
return view('user::role.create', $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|max:255',
|
||||
]);
|
||||
|
||||
Permission::create($validated);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Permissions Created Successfully.'], 200);
|
||||
}
|
||||
return redirect()->route('permissions.index')->with('success', 'The Permissions created Successfully.');
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
$idOrder = $request->input('id_order');
|
||||
|
||||
foreach ($idOrder as $index => $id) {
|
||||
$companyArticle = Permission::find($id);
|
||||
$companyArticle->display_order = $index + 1;
|
||||
$companyArticle->save();
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200);
|
||||
}
|
||||
public function updatealias(Request $request)
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
|
||||
$articleId = $request->input('articleId');
|
||||
$newAlias = $request->input('newAlias');
|
||||
$companyArticle = Permission::find($articleId);
|
||||
if (!$companyArticle) {
|
||||
return response()->json(['status' => false, 'content' => 'Company article not found.'], 404);
|
||||
}
|
||||
$companyArticle->alias = $newAlias;
|
||||
$companyArticle->save();
|
||||
return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function show(Request $request, $id)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Permission $permission)
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'show', ' Permissions show');
|
||||
$data = Permission::findOrFail($id);
|
||||
|
||||
return view("crud.generated.permissions.show", compact('data'));
|
||||
$data['title'] = "Edit Role";
|
||||
$data['editable'] = true;
|
||||
$data['role'] = $this->role->getRoleById($id);
|
||||
$data['permissionIDsArray'] = $data['role']?->permissions?->pluck('id')->toArray();
|
||||
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
||||
return view('user::role.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'edit', ' Permissions edit');
|
||||
$TableData = Permission::get();
|
||||
$data = Permission::findOrFail($id);
|
||||
if ($request->ajax()) {
|
||||
$html = view("crud.generated.permissions.ajax.edit", compact('data'))->render();
|
||||
return response()->json(['status' => true, 'content' => $html], 200);
|
||||
}
|
||||
return view("crud.generated.permissions.edit", compact('data', 'TableData'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Permission $permission)
|
||||
{
|
||||
|
||||
$validated = $request->validate(['name' => 'required']);
|
||||
|
||||
$permission->update($validated);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Permissions updated Successfully.'], 200);
|
||||
}
|
||||
// return redirect()->route('permissions.index')->with('success','The Permissions updated Successfully.');
|
||||
return redirect()->route('permissions.index')->with('success', 'The Permissions updated successfully.');
|
||||
//
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id)
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'destroy', ' Permissions destroy');
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$OperationNumber = getOperationNumber();
|
||||
$this->modelService->destroy($OperationNumber, $OperationNumber, $id);
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
createErrorLog(PermissionsController::class, 'destroy', $e->getMessage());
|
||||
return response()->json(['status' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['status' => true, 'message' => 'The Permissions Deleted Successfully.'], 200);
|
||||
$permissionDelete = $this->permissionRepository->getPermissionById($id);
|
||||
|
||||
$permissionDelete->delete();
|
||||
return response()->json(['status' => true, 'message' => 'Permission has been deleted'] );
|
||||
}
|
||||
public function toggle(Request $request, $id)
|
||||
|
||||
public function generatePermissionFromRoutes()
|
||||
{
|
||||
createActivityLog(PermissionsController::class, 'destroy', ' Permissions destroy');
|
||||
$data = Permission::findOrFail($id);
|
||||
$requestData = ['status' => ($data->status == 1) ? 0 : 1];
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$OperationNumber = getOperationNumber();
|
||||
$this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id);
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
createErrorLog(PermissionsController::class, 'destroy', $e->getMessage());
|
||||
return response()->json(['status' => false, 'message' => $e->getMessage()], 500);
|
||||
$this->permissionRepository->generatePermissionFromRoutes();
|
||||
toastr()->success('Permission generated successfully!');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['status' => true, 'message' => 'The Permissions Deleted Successfully.'], 200);
|
||||
return to_route('permissions.index');
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,123 +3,101 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\PermissionRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Roles;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Service\CommonModelService;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Brian2694\Toastr\Facades\Toastr;
|
||||
use App\Repositories\RoleRepository;
|
||||
use Log;
|
||||
use Exception;
|
||||
|
||||
class RolesController extends Controller
|
||||
{
|
||||
protected $modelService;
|
||||
public function __construct(Roles $model)
|
||||
{
|
||||
$this->modelService = new CommonModelService($model);
|
||||
private $roleRepository;
|
||||
private $permissionRepository;
|
||||
public function __construct(
|
||||
RoleRepository $roleRepository,
|
||||
PermissionRepository $permissionRepository
|
||||
) {
|
||||
$this->roleRepository = $roleRepository;
|
||||
$this->permissionRepository = $permissionRepository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$data['title'] = "List Roles";
|
||||
createActivityLog(RolesController::class, 'index', ' Roles index');
|
||||
$data = Role::whereNotIn('name', ['admin'])->get();
|
||||
$roles = $this->roleRepository->findAll();
|
||||
|
||||
return view("crud.generated.roles.index", compact('data'));
|
||||
return view("crud.generated.roles.index", compact('roles'));
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
public function create()
|
||||
{
|
||||
createActivityLog(RolesController::class, 'create', ' Roles create');
|
||||
$TableData = Roles::get();
|
||||
$permissions = Permission::all();
|
||||
return view("crud.generated.roles.create", compact('TableData', 'permissions'));
|
||||
$data['title'] = "Create Role";
|
||||
$data['editable'] = false;
|
||||
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
||||
return view('crud.generated.roles.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate(['name' => ['required', 'min:3']]);
|
||||
$role = Role::create($validated);
|
||||
try {
|
||||
|
||||
if ($role->hasPermissionTo($request->permission, 'web')) {
|
||||
return back()->with('message', 'Permission exists.');
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required',
|
||||
'guard_name' => 'string',
|
||||
]);
|
||||
|
||||
$role = $this->roleRepository->create($validatedData);
|
||||
|
||||
$role->permissions()->attach($request->permissions);
|
||||
|
||||
Toastr::success('New Role has been created', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
} catch (\Throwable $th) {
|
||||
Toastr::success('Error while creating', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
}
|
||||
$role->givePermissionTo($request->permission);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Roles Created Successfully.'], 200);
|
||||
}
|
||||
return redirect()->route('roles.index')->with('success', 'The Roles created Successfully.');
|
||||
return redirect()->route('roles.index');
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
public function show(string $id)
|
||||
{
|
||||
$idOrder = $request->input('id_order');
|
||||
|
||||
foreach ($idOrder as $index => $id) {
|
||||
$companyArticle = Roles::find($id);
|
||||
$companyArticle->display_order = $index + 1;
|
||||
$companyArticle->save();
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200);
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function show(Request $request, $id)
|
||||
public function edit($id)
|
||||
{
|
||||
createActivityLog(RolesController::class, 'show', ' Roles show');
|
||||
$data = Roles::findOrFail($id);
|
||||
|
||||
return view("crud.generated.roles.show", compact('data'));
|
||||
$data['title'] = "Edit Role";
|
||||
$data['editable'] = false;
|
||||
$data['role'] = $this->roleRepository->getRoleById($id);
|
||||
$data['permissionIDsArray'] = $data['role']?->permissions?->pluck('id')->toArray();
|
||||
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
||||
return view('crud.generated.roles.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
createActivityLog(RolesController::class, 'edit', ' Roles edit');
|
||||
$permissions = Permission::all();
|
||||
$TableData = Role::get();
|
||||
$data = Role::findOrFail($id);
|
||||
if ($request->ajax()) {
|
||||
$html = view("crud.generated.roles.ajax.edit", compact('data'))->render();
|
||||
return response()->json(['status' => true, 'content' => $html], 200);
|
||||
try {
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required',
|
||||
'guard_name' => 'string',
|
||||
]);
|
||||
|
||||
$role = $this->roleRepository->update($id, $validatedData);
|
||||
$role->permissions()->sync($request->permissions);
|
||||
|
||||
Toastr::success('Role has been updated', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
} catch (\Throwable $th) {
|
||||
Toastr::success('Error while updating', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
}
|
||||
return view("crud.generated.roles.edit", compact('data', 'TableData', 'permissions'));
|
||||
return redirect()->route('roles.index');
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Role $role)
|
||||
public function destroy($id)
|
||||
{
|
||||
$permission = $request->permission;
|
||||
$validated = $request->validate(['name' => ['required', 'min:3']]);
|
||||
$role->update($validated);
|
||||
|
||||
if($permission){
|
||||
$role->givePermissionTo($permission);
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The Roles updated Successfully.'], 200);
|
||||
}
|
||||
// return redirect()->route('roles.index')->with('success','The Roles updated Successfully.');
|
||||
return redirect()->back()->with('success', 'The Roles updated successfully.');
|
||||
}
|
||||
|
||||
public function destroy(Role $role)
|
||||
{
|
||||
$role->delete();
|
||||
return response()->json(['status' => true, 'message' => 'The Roles Deleted Successfully.'], 200);
|
||||
}
|
||||
|
||||
public function revokePermission(Role $role, Permission $permission)
|
||||
{
|
||||
if ($role->hasPermissionTo($permission)) {
|
||||
$role->revokePermissionTo($permission);
|
||||
return back()->with('message', 'Permission revoked.');
|
||||
}
|
||||
return back()->with('message', 'Permission not exists.');
|
||||
$this->roleRepository->delete($id);
|
||||
Toastr::success('Role has been deleted', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
return response()->json(['status' => true, 'message' => 'Role has been deleted!']);
|
||||
}
|
||||
}
|
||||
|
@ -3,115 +3,135 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\RoleInterface;
|
||||
use App\Repositories\RoleRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use App\Service\CommonModelService;
|
||||
use Log;
|
||||
use Exception;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Brian2694\Toastr\Facades\Toastr;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
protected $modelService;
|
||||
protected $userRepository;
|
||||
protected $employeeRepository;
|
||||
protected $roleRepository;
|
||||
|
||||
public function __construct(User $model)
|
||||
public function __construct(UserRepository $userRepository, RoleRepository $roleRepository)
|
||||
{
|
||||
$this->modelService = new CommonModelService($model);
|
||||
$this->userRepository = $userRepository;
|
||||
$this->roleRepository = $roleRepository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
public function index()
|
||||
{
|
||||
createActivityLog(UsersController::class, 'index', 'User index');
|
||||
$data = User::get();
|
||||
return view("crud.generated.users.index", compact('data'));
|
||||
$data['users'] = $this->userRepository->findAll();
|
||||
$data['editable'] = false;
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
return view('crud.generated.users.index', $data);
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
createActivityLog(UsersController::class, 'show', 'User show');
|
||||
$data = User::findOrFail($id);
|
||||
return view("crud.generated.User.show", compact('data'));
|
||||
$data['title'] = "Create User";
|
||||
$data['editable'] = false;
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
return view('crud.generated.users.create', $data);
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
createActivityLog(UsersController::class, 'edit', 'User edit');
|
||||
$TableData = User::get();
|
||||
$data = User::findOrFail($id);
|
||||
$roles = Role::all();
|
||||
$permissions = Permission::all();
|
||||
// try {
|
||||
|
||||
if ($request->ajax()) {
|
||||
$html = view("crud.generated.User.ajax.edit", compact('data'))->render();
|
||||
return response()->json(['status' => true, 'content' => $html], 200);
|
||||
}
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|min:5',
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
return view("crud.generated.users.edit", compact('data', 'TableData', 'roles', 'permissions'));
|
||||
$validated['password'] = bcrypt($validated['password']);
|
||||
|
||||
$this->userRepository->create($validated, $request->role);
|
||||
|
||||
Toastr::success('User has been created successfully.', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
|
||||
// } catch (\Throwable $th) {
|
||||
|
||||
// echo $th->getMessage();
|
||||
|
||||
// toastr()->error($th->getMessage());
|
||||
|
||||
// }
|
||||
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user)
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
// dd($request->toArray());
|
||||
|
||||
if ($request->permission) {
|
||||
if ($user->hasPermissionTo($request->permission)) {
|
||||
return redirect()->back()->with('error', 'The User already has this permission.');
|
||||
}
|
||||
$user->givePermissionTo($request->permission);
|
||||
}
|
||||
if ($request->role) {
|
||||
if ($user->hasRole($request->role)) {
|
||||
return redirect()->back()->with('error', 'The User already has this role.');
|
||||
}
|
||||
$user->assignRole($request->role);
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['status' => true, 'message' => 'The User updated Successfully.'], 200);
|
||||
}
|
||||
|
||||
// Logic to update user should be added here
|
||||
|
||||
return redirect()->back()->with('success', 'The User updated successfully.');
|
||||
$data['user'] = $this->userRepository->getUserById($id);
|
||||
return view('user::user.show');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
createActivityLog(UsersController::class, 'destroy', 'User destroy');
|
||||
DB::beginTransaction();
|
||||
$data['title'] = "Edit User";
|
||||
$data['editable'] = true;
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
$data['user'] = $this->userRepository->getUserById($id);
|
||||
return view('crud.generated.users.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$OperationNumber = getOperationNumber();
|
||||
$this->modelService->destroy($OperationNumber, $OperationNumber, $id);
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
createErrorLog(UsersController::class, 'destroy', $e->getMessage());
|
||||
return response()->json(['status' => false, 'message' => $e->getMessage()], 500);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|min:5',
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
$validated['password'] = bcrypt($validated['password']);
|
||||
|
||||
$this->userRepository->update($id, $validated, $request->role);
|
||||
|
||||
Toastr::success('User has been updated', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->json(['status' => true, 'message' => 'The User Deleted Successfully.'], 200);
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
public function removeRole(User $user, Role $role)
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
if ($user->hasRole($role)) {
|
||||
$user->removeRole($role);
|
||||
return back()->with('message', 'Role removed.');
|
||||
}
|
||||
try {
|
||||
|
||||
return back()->with('message', 'Role not exists.');
|
||||
}
|
||||
$this->userRepository->delete($id);
|
||||
|
||||
public function revokePermission(User $user, Permission $permission)
|
||||
{
|
||||
if ($user->hasPermissionTo($permission)) {
|
||||
$user->revokePermissionTo($permission);
|
||||
return back()->with('message', 'Permission revoked.');
|
||||
Toastr::success('User has been deleted', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
Toastr::success('Error deleting user', 'Title', ["positionClass" => "toast-top-center"]);
|
||||
}
|
||||
return back()->with('message', 'Permission does not exists.');
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Mail\sendEmail;
|
||||
use App\Models\Advertisements;
|
||||
use App\Models\Articles;
|
||||
use App\Models\Comments;
|
||||
use App\Models\Economies;
|
||||
use App\Models\Horoscopes;
|
||||
use App\Models\Menuitems;
|
||||
@ -18,6 +19,7 @@ use App\Models\Teams;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Models\Videos;
|
||||
use Share;
|
||||
|
||||
@ -27,6 +29,13 @@ class WebsiteController extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$routes = Route::getRoutes();
|
||||
// dd($routes);
|
||||
// foreach ($routes as $route) {
|
||||
// $name= $route->getName();
|
||||
// dump($name);
|
||||
// }
|
||||
// dd('end');
|
||||
$this->path = config('app.client_path');
|
||||
|
||||
$headerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 1])->with('children')->orderBy('display_order')->get();
|
||||
@ -36,6 +45,8 @@ class WebsiteController extends Controller
|
||||
$ads = Advertisements::where('status', 1)->where('parent_advertisement', 0)->get();
|
||||
$adsWithChildren = Advertisements::where('status', 1)->where('parent_advertisement', 0)->orderBy('display_order')->with('children')->get();
|
||||
$popup = Popups::where('status',1)->latest()->first();
|
||||
$route = Route::getRoutes();
|
||||
|
||||
View::share(
|
||||
[
|
||||
'headerMenuItems' => $headerMenuItems,
|
||||
@ -104,7 +115,8 @@ class WebsiteController extends Controller
|
||||
|
||||
$news->views_count = $news->views_count + 1;
|
||||
$news->save();
|
||||
|
||||
$newsWithComment = News::with('comments')->where('news_id', $news->news_id)->get();
|
||||
// dd($newsWithComment->toArray());
|
||||
$recentNews = News::where('status', 1)
|
||||
->where('news_id', '!=', $news->news_id)
|
||||
->inRandomOrder()
|
||||
@ -112,7 +124,7 @@ class WebsiteController extends Controller
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return view($this->path . '.news-detail', compact('news', 'recentNews','shareComponent'));
|
||||
return view($this->path . '.news-detail', compact('news', 'recentNews','shareComponent','newsWithComment'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,6 +36,7 @@ class Kernel extends HttpKernel
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\PermissionMiddleware::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
@ -64,8 +65,8 @@ class Kernel extends HttpKernel
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
|
||||
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
|
||||
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
|
||||
// 'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
|
||||
'permission' => \App\Http\Middleware\PermissionMiddleware::class,
|
||||
// 'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
|
||||
];
|
||||
}
|
||||
|
62
app/Http/Middleware/PermissionMiddleware.php
Normal file
62
app/Http/Middleware/PermissionMiddleware.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\Permission\Exceptions\UnauthorizedException;
|
||||
use Spatie\Permission\Guard;
|
||||
|
||||
class PermissionMiddleware
|
||||
{
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$authGuard = Auth::guard($guard);
|
||||
|
||||
$user = $authGuard->user();
|
||||
|
||||
// For machine-to-machine Passport clients
|
||||
if (!$user && $request->bearerToken() && config('permission.use_passport_client_credentials')) {
|
||||
|
||||
$user = Guard::getPassportClient($guard);
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
|
||||
throw UnauthorizedException::notLoggedIn();
|
||||
}
|
||||
|
||||
if (!method_exists($user, 'hasAnyPermission')) {
|
||||
|
||||
throw UnauthorizedException::missingTraitHasRoles($user);
|
||||
}
|
||||
|
||||
// if ($user->hasRole('admin')) {
|
||||
// return $next($request);
|
||||
// }
|
||||
|
||||
foreach ($user->roles as $role) {
|
||||
if ($role->hasPermissionTo($request->route()->getName())) {
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
throw UnauthorizedException::forPermissions($user->getAllPermissions()->toArray());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the permission and guard for the middleware.
|
||||
*
|
||||
* @param array|string $permission
|
||||
* @param string|null $guard
|
||||
* @return string
|
||||
*/
|
||||
public static function using($permission, $guard = null)
|
||||
{
|
||||
$permissionString = is_string($permission) ? $permission : implode('|', $permission);
|
||||
$args = is_null($guard) ? $permissionString : "$permissionString,$guard";
|
||||
|
||||
return static::class . ':' . $args;
|
||||
}
|
||||
}
|
53
app/Models/Comments.php
Normal file
53
app/Models/Comments.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\CreatedUpdatedBy;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Comments extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'users_id',
|
||||
'news_id',
|
||||
'content',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
|
||||
];
|
||||
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
protected function getStatusNameAttribute()
|
||||
{
|
||||
return $this->status == 1 ? '<span class="badge text-bg-success-soft"> Active </span>' : '<span class="badge text-bg-danger-soft">Inactive</span>';
|
||||
}
|
||||
|
||||
|
||||
public function news():BelongsTo{
|
||||
|
||||
return $this->belongsTo(News::class,'news_id','news_id');
|
||||
}
|
||||
|
||||
public function parent(){
|
||||
return $this->belongsTo(Comments::class,'parent_id');
|
||||
}
|
||||
|
||||
public function subComments(){
|
||||
return $this->hasMany(Comments::class,'parent_id');
|
||||
}
|
||||
|
||||
public function user(){
|
||||
return $this->belongsTo(User::class, 'users_id', 'id');
|
||||
}
|
||||
|
||||
}
|
@ -89,4 +89,12 @@ class News extends Model
|
||||
public function provinces(): BelongsTo{
|
||||
return $this->belongsTo(Provinces::class, 'provinces_id', 'province_id');
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comments::class, 'news_id', 'news_id')->with('subcomments')
|
||||
->where('parent_id', 0)
|
||||
->orWhere('parent_id', null)
|
||||
->where('status', 1);
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,8 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
public function comments(){
|
||||
return $this->hasMany(Comments::class,'users_id','id');
|
||||
}
|
||||
}
|
||||
|
@ -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