feat: add bylaw management features including documents, legal authorities, subject categories, and nodes
This commit is contained in:
@@ -85,7 +85,7 @@ class ArtController extends Controller
|
||||
{
|
||||
$art = Art::select('id', 'title', 'number', 'text', 'law_id')->find($id);
|
||||
|
||||
if (!$art) {
|
||||
if (! $art) {
|
||||
return $this->failed([], 'Art not found');
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
$art->is_like = $this->isLiked($art->id);
|
||||
$art->note = Note::select('id', 'note', 'color_code','created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
|
||||
$art->note = Note::select('id', 'note', 'color_code', 'created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
|
||||
$art->category = $law?->category?->name;
|
||||
$art->route = array_values($this->route(Art::class, $art));
|
||||
|
||||
$previousArt = Art::select('id', 'title', 'number', 'text', 'law_id')
|
||||
->where('law_id',$art->law_id)
|
||||
->where('law_id', $art->law_id)
|
||||
->where('number', '<', $art->number)
|
||||
->orderBy('number', 'desc')
|
||||
->first();
|
||||
@@ -115,7 +115,7 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
$nextArt = Art::select('id', 'title', 'number', 'text', 'law_id')
|
||||
->where('law_id',$art->law_id)
|
||||
->where('law_id', $art->law_id)
|
||||
->where('number', '>', $art->number)
|
||||
->orderBy('number')
|
||||
->first();
|
||||
@@ -155,7 +155,6 @@ class ArtController extends Controller
|
||||
return $this->success(null, 'Success', 'Art liked successfully');
|
||||
}
|
||||
|
||||
|
||||
private function isLiked($art_id): bool
|
||||
{
|
||||
return LikeArt::query()->where('art_id', $art_id)
|
||||
@@ -165,7 +164,7 @@ class ArtController extends Controller
|
||||
|
||||
private function isLockedForCurrentUser(?Law $law): bool
|
||||
{
|
||||
return !auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
||||
return ! auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
||||
}
|
||||
|
||||
public function likes()
|
||||
@@ -179,14 +178,13 @@ class ArtController extends Controller
|
||||
return [
|
||||
'id' => $q->art->id,
|
||||
'title' => $q->art->title,
|
||||
'text' => $isLocked ? null : $q->art->text
|
||||
'text' => $isLocked ? null : $q->art->text,
|
||||
];
|
||||
});
|
||||
|
||||
return $this->success($likes);
|
||||
}
|
||||
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
@@ -201,7 +199,7 @@ class ArtController extends Controller
|
||||
'branch_id' => 'nullable|array',
|
||||
'category_id' => 'nullable|int',
|
||||
'per_page' => 'nullable|integer',
|
||||
'search' => 'nullable|string'
|
||||
'search' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$models = [
|
||||
@@ -214,7 +212,7 @@ class ArtController extends Controller
|
||||
Part::class,
|
||||
Gate::class,
|
||||
Branch::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$results = [];
|
||||
@@ -238,13 +236,13 @@ class ArtController extends Controller
|
||||
'part_id',
|
||||
'gate_id',
|
||||
'chapter_id',
|
||||
'branch_id'
|
||||
'branch_id',
|
||||
];
|
||||
|
||||
$model = new $modelClass;
|
||||
if ($model->getTable() == 'art') {
|
||||
$query->where(function ($query) use ($validated, $filters) {
|
||||
if (!empty($validated['search'])) {
|
||||
if (! empty($validated['search'])) {
|
||||
$query->where(function ($q) use ($validated) {
|
||||
$q->where('title', 'LIKE', "%{$validated['search']}%")
|
||||
->orWhere('text', 'LIKE', "%{$validated['search']}%");
|
||||
@@ -252,14 +250,13 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (!empty($validated[$filter])) {
|
||||
if (! empty($validated[$filter])) {
|
||||
$query->whereIn($filter, $validated[$filter]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!empty($validated['category_id'])) {
|
||||
if (! empty($validated['category_id'])) {
|
||||
$query->whereIn('law_id', Category::where('type', $this->convertValueTo($validated['category_id']))->get()->pluck('id'));
|
||||
}
|
||||
|
||||
@@ -268,8 +265,8 @@ class ArtController extends Controller
|
||||
return $items->map(function ($item) use ($validated, $modelClass) {
|
||||
$text = $item->text ?? '';
|
||||
$search = preg_quote($validated['search'] ?? '', '/');
|
||||
if (!empty($text) && preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1] ?? '') . ' ' . $matches[2] . ' ' . trim($matches[3] ?? '');
|
||||
if (! empty($text) && preg_match('/\b(.{0,50})\b('.$search.')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1] ?? '').' '.$matches[2].' '.trim($matches[3] ?? '');
|
||||
} else {
|
||||
$context = $text;
|
||||
}
|
||||
@@ -289,11 +286,11 @@ class ArtController extends Controller
|
||||
'count_art' => $law->arts->count(),
|
||||
'count_volums' => $law->volums->count(),
|
||||
'price' => $law->price,
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
})->toArray();
|
||||
} else {
|
||||
$query = $query->where('title', 'LIKE', '%' . ($validated['search'] ?? '') . '%');
|
||||
$query = $query->where('title', 'LIKE', '%'.($validated['search'] ?? '').'%');
|
||||
}
|
||||
|
||||
$items = $query->paginate($validated['per_page'] ?? 10);
|
||||
@@ -306,21 +303,21 @@ class ArtController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'category' => optional($law?->category)?->name ?? '',
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
} else if ((new $modelClass)->getTable() == 'art') {
|
||||
} elseif ((new $modelClass)->getTable() == 'art') {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'law' => $law?->title ?? '',
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
@@ -328,7 +325,7 @@ class ArtController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'law' => $law?->title ?? '',
|
||||
];
|
||||
@@ -336,8 +333,6 @@ class ArtController extends Controller
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function route($modelClass, $query)
|
||||
{
|
||||
if ((new $modelClass)->getTable() == 'art') {
|
||||
@@ -350,12 +345,14 @@ class ArtController extends Controller
|
||||
Chapter::find($query->chapter_id)?->title,
|
||||
Part::find($query->part_id)?->title,
|
||||
Gate::find($query->gate_id)?->title,
|
||||
Branch::find($query->branch_id)?->title
|
||||
Branch::find($query->branch_id)?->title,
|
||||
]);
|
||||
|
||||
$route = array_values($route);
|
||||
|
||||
return $route;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -365,7 +362,7 @@ class ArtController extends Controller
|
||||
|
||||
$models = [
|
||||
Law::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$results = [];
|
||||
@@ -374,7 +371,6 @@ class ArtController extends Controller
|
||||
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
|
||||
}
|
||||
|
||||
|
||||
$models_other = [
|
||||
Volum::class,
|
||||
Book::class,
|
||||
@@ -388,13 +384,12 @@ class ArtController extends Controller
|
||||
|
||||
$found = false;
|
||||
foreach ($models_other as $modelClass) {
|
||||
if (count($this->searchModelFastSearch($modelClass, $search)) > 0 && !$found) {
|
||||
if (count($this->searchModelFastSearch($modelClass, $search)) > 0 && ! $found) {
|
||||
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$models = [
|
||||
Law::class,
|
||||
Volum::class,
|
||||
@@ -405,7 +400,7 @@ class ArtController extends Controller
|
||||
Part::class,
|
||||
Gate::class,
|
||||
Branch::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$count_all = 0;
|
||||
@@ -414,7 +409,6 @@ class ArtController extends Controller
|
||||
$count_all += count($this->searchModel($modelClass, $search));
|
||||
}
|
||||
|
||||
|
||||
return $this->success(['items' => $results, 'count' => $count_all]);
|
||||
}
|
||||
|
||||
@@ -449,7 +443,7 @@ class ArtController extends Controller
|
||||
'title' => $q->title,
|
||||
'type' => $table === 'section' ? 'sections' : $table,
|
||||
'category' => $category,
|
||||
'law' => Law::where('id', $q->law_id)->first()?->title
|
||||
'law' => Law::where('id', $q->law_id)->first()?->title,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -458,7 +452,7 @@ class ArtController extends Controller
|
||||
'title' => $q->title,
|
||||
'type' => $table === 'section' ? 'sections' : $table,
|
||||
'category' => $category,
|
||||
'image' => Law::where('id', $q->id)->first()?->image
|
||||
'image' => Law::where('id', $q->id)->first()?->image,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -474,13 +468,13 @@ class ArtController extends Controller
|
||||
Chapter::find($q->chapter_id)?->title,
|
||||
Part::find($q->part_id)?->title,
|
||||
Gate::find($q->gate_id)?->title,
|
||||
Branch::find($q->branch_id)?->title
|
||||
Branch::find($q->branch_id)?->title,
|
||||
]);
|
||||
|
||||
$text = $q->text;
|
||||
$search = preg_quote($search, '/');
|
||||
if (preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1]) . ' ' . $matches[2] . ' ' . trim($matches[3]);
|
||||
if (preg_match('/\b(.{0,50})\b('.$search.')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1]).' '.$matches[2].' '.trim($matches[3]);
|
||||
} else {
|
||||
$context = $text;
|
||||
}
|
||||
@@ -499,7 +493,7 @@ class ArtController extends Controller
|
||||
'count_art' => $law->arts->count(),
|
||||
'count_volum' => $law->volums->count(),
|
||||
'price' => $law->price,
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class AuthController extends Controller
|
||||
return User::create([
|
||||
'name' => 'Law',
|
||||
'mobile' => $request->mobile,
|
||||
'email' => 'law' . $request->mobile . '@law.com',
|
||||
'email' => 'law'.$request->mobile.'@law.com',
|
||||
'password' => Hash::make($request->mobile),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\BookRequest;
|
||||
use App\Models\Book;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Traits\BaseApiResponse;
|
||||
|
||||
class BookController extends Controller
|
||||
@@ -24,7 +23,7 @@ class BookController extends Controller
|
||||
|
||||
$books->getCollection()->transform(function ($section) {
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked ?? false;
|
||||
|
||||
|
||||
unset($section['law_id']);
|
||||
unset($section['volum_id']);
|
||||
|
||||
|
||||
@@ -12,13 +12,12 @@ class CategoriesController extends Controller
|
||||
use BaseApiResponse;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
{
|
||||
$perPage = $request->input('per_page', 15);
|
||||
$page = $request->input('page', 1);
|
||||
|
||||
$categories = Category::paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
|
||||
return $this->success($categories->items());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ChapterRequest;
|
||||
use App\Models\Chapter;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Traits\BaseApiResponse;
|
||||
|
||||
class ChapterController extends Controller
|
||||
@@ -20,7 +19,7 @@ class ChapterController extends Controller
|
||||
$perPage = $validated['per_page'] ?? 15;
|
||||
$page = $validated['page'] ?? 1;
|
||||
|
||||
$chapters = Chapter::where('book_id' , $validated['book_id'])->paginate($perPage, ['*'], 'page', $page);
|
||||
$chapters = Chapter::where('book_id', $validated['book_id'])->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
$chapters->getCollection()->transform(function ($section) {
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Http\Controllers\api;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Folder;
|
||||
use App\Models\FolderArt;
|
||||
use App\Models\Law;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -18,26 +17,25 @@ class FolderController extends Controller
|
||||
$folder = Folder::query()->where('user_id', auth()->id())->get()
|
||||
->map(function ($q) {
|
||||
return [
|
||||
"id" => $q->id,
|
||||
"name" => $q->name,
|
||||
"count_of_arts" => $q->arts->count(),
|
||||
"created_at" => $q->created_at,
|
||||
'id' => $q->id,
|
||||
'name' => $q->name,
|
||||
'count_of_arts' => $q->arts->count(),
|
||||
'created_at' => $q->created_at,
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return $this->success($folder);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validted = $request->validate([
|
||||
'name' => 'required'
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
Folder::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'name' => $validted['name']
|
||||
'name' => $validted['name'],
|
||||
]);
|
||||
|
||||
return $this->success([], 'ایجاد شد', 'پوشه با موفقیت ایجاد شد.');
|
||||
@@ -47,7 +45,7 @@ class FolderController extends Controller
|
||||
{
|
||||
$validted = $request->validate([
|
||||
'folder_id' => 'required',
|
||||
'art_id' => 'required'
|
||||
'art_id' => 'required',
|
||||
]);
|
||||
|
||||
if (Folder::query()->where('id', $validted['folder_id'])->count() == 0) {
|
||||
@@ -60,7 +58,7 @@ class FolderController extends Controller
|
||||
|
||||
FolderArt::create([
|
||||
'folder_id' => $validted['folder_id'],
|
||||
'art_id' => $validted['art_id']
|
||||
'art_id' => $validted['art_id'],
|
||||
]);
|
||||
|
||||
return $this->success([], 'اضافه شد', 'ارت با موفیت اضافه شد');
|
||||
@@ -79,11 +77,11 @@ class FolderController extends Controller
|
||||
$shortText = '';
|
||||
if (strlen($text) > 50) {
|
||||
$shortText = substr($text, 0, 50);
|
||||
$shortText = substr($shortText, 0, strrpos($shortText, ' ')) . '...';
|
||||
$shortText = substr($shortText, 0, strrpos($shortText, ' ')).'...';
|
||||
} else {
|
||||
$shortText = $text;
|
||||
}
|
||||
$isLocked = !auth()->user()->isSubscriber() && (bool) $art->law?->is_locked;
|
||||
$isLocked = ! auth()->user()->isSubscriber() && (bool) $art->law?->is_locked;
|
||||
|
||||
return [
|
||||
'id' => $art->id,
|
||||
@@ -138,15 +136,17 @@ class FolderController extends Controller
|
||||
return $this->failed('پوشه یافت نشد', 'پوشه مورد نظر یافت نشد', 404);
|
||||
}
|
||||
Folder::query()->where('id', $id)->delete();
|
||||
|
||||
return $this->success([], 'حذف شد', 'پوشه با موفقیت حذف شد');
|
||||
}
|
||||
|
||||
public function delete_art($id,$art_id)
|
||||
public function delete_art($id, $art_id)
|
||||
{
|
||||
if (FolderArt::query()->where('folder_id', $id)->where('art_id', $art_id)->count() == 0) {
|
||||
return $this->failed([], 'ارت مورد نظر یافت نشد', 404);
|
||||
}
|
||||
FolderArt::query()->where('folder_id', $id)->where('art_id', $art_id)->delete();
|
||||
|
||||
return $this->success([], 'حذف شد', 'ارت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ChapterRequest;
|
||||
use App\Models\Gate;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GateController extends Controller
|
||||
{
|
||||
@@ -23,15 +21,13 @@ class GateController extends Controller
|
||||
|
||||
$gates->getCollection()->transform(function ($gate) {
|
||||
unset($gate['book_id']);
|
||||
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $gate['law_id'])->first()?->is_locked;
|
||||
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $gate['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($gate['law_id']);
|
||||
|
||||
return $gate;
|
||||
});
|
||||
|
||||
|
||||
|
||||
return $this->success($gates->items());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class HomeController extends Controller
|
||||
return [
|
||||
'id' => $q->law?->id,
|
||||
'name' => $q->law?->title,
|
||||
'is_locked' => $q->law?->is_locked
|
||||
'is_locked' => $q->law?->is_locked,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ class HomeController extends Controller
|
||||
return [
|
||||
'id' => $q->id,
|
||||
'name' => $q->title,
|
||||
'is_locked' => $q->is_locked
|
||||
'is_locked' => $q->is_locked,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -49,13 +49,13 @@ class HomeController extends Controller
|
||||
$q->where('type', $category);
|
||||
})->get()->map(function ($q) {
|
||||
return [
|
||||
"id" => $q->id,
|
||||
"title" => $q->title,
|
||||
"is_locked" => $q->is_locked,
|
||||
"category_id" => $q->category_id,
|
||||
"price" => $q->price,
|
||||
"image" => $q->image,
|
||||
"type" => 'law'
|
||||
'id' => $q->id,
|
||||
'title' => $q->title,
|
||||
'is_locked' => $q->is_locked,
|
||||
'category_id' => $q->category_id,
|
||||
'price' => $q->price,
|
||||
'image' => $q->image,
|
||||
'type' => 'law',
|
||||
];
|
||||
});
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class HomeController extends Controller
|
||||
return [
|
||||
'id' => $q->id,
|
||||
'name' => $q->title,
|
||||
'is_locked' => $q->is_locked
|
||||
'is_locked' => $q->is_locked,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -83,7 +83,7 @@ class HomeController extends Controller
|
||||
'name' => $freeSubscription->subscribe->name,
|
||||
'price' => $freeSubscription->subscribe->price,
|
||||
'expired_day' => $freeSubscription->expired_at->diffInDays(now()),
|
||||
'is_free' => true
|
||||
'is_free' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -92,7 +92,9 @@ class HomeController extends Controller
|
||||
->latest('expired_at')
|
||||
->first();
|
||||
|
||||
$expiredDays = UserSubscriber::query()->where('user_id', $user->id)->where('expired_at', '>=', now())->get()->sum(function ($subscriber) {return $subscriber->expired_at->diffInDays(now());});
|
||||
$expiredDays = UserSubscriber::query()->where('user_id', $user->id)->where('expired_at', '>=', now())->get()->sum(function ($subscriber) {
|
||||
return $subscriber->expired_at->diffInDays(now());
|
||||
});
|
||||
|
||||
if ($latestSubscription) {
|
||||
$current_plan = [
|
||||
@@ -100,7 +102,7 @@ class HomeController extends Controller
|
||||
'name' => $latestSubscription->subscribe->name ?? 'Subscription',
|
||||
'price' => $latestSubscription->subscribe->price ?? 100,
|
||||
'expired_day' => $expiredDays,
|
||||
'is_free' => (bool) $latestSubscription->is_free
|
||||
'is_free' => (bool) $latestSubscription->is_free,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -119,9 +121,9 @@ class HomeController extends Controller
|
||||
private function refreshMarketSubscriptionAfterResponse($user): void
|
||||
{
|
||||
$cacheKey = "home-market-refresh-user-{$user->id}";
|
||||
$this->refreshMarketSubscription($user);
|
||||
$this->refreshMarketSubscription($user);
|
||||
|
||||
if (!Cache::add($cacheKey, true, now()->addHours(24))) {
|
||||
if (! Cache::add($cacheKey, true, now()->addHours(24))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,6 +166,6 @@ class HomeController extends Controller
|
||||
return true;
|
||||
}
|
||||
|
||||
return !$subscriber->last_verified_at || $subscriber->last_verified_at->lessThan(now()->subHours(12));
|
||||
return ! $subscriber->last_verified_at || $subscriber->last_verified_at->lessThan(now()->subHours(12));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ class LawController extends Controller
|
||||
{
|
||||
$perPage = $request->input('per_page', 15);
|
||||
$page = $request->input('page', 1);
|
||||
|
||||
|
||||
$laws = Law::simplePaginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
|
||||
return $this->success($laws->items(), 'Success');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class NoteController extends Controller
|
||||
$validated = $request->validate([
|
||||
'art_id' => 'required',
|
||||
'note' => 'required',
|
||||
'color_code' => 'nullable'
|
||||
'color_code' => 'nullable',
|
||||
]);
|
||||
|
||||
Note::query()->create(
|
||||
@@ -36,7 +36,7 @@ class NoteController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'note' => 'required',
|
||||
'color_code' => 'nullable'
|
||||
'color_code' => 'nullable',
|
||||
]);
|
||||
|
||||
$note = Note::findOrFail($id);
|
||||
|
||||
@@ -5,34 +5,31 @@ namespace App\Http\Controllers\api;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ChapterRequest;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Models\Part;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PartController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function index(ChapterRequest $request)
|
||||
{
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
|
||||
$perPage = $request->input('per_page', 15);
|
||||
$page = $request->input('page', 1);
|
||||
|
||||
$parts = Part::where('book_id' , $request->input('book_id'))->paginate($perPage, ['*'], 'page', $page);
|
||||
$parts = Part::where('book_id', $request->input('book_id'))->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
$parts->getCollection()->transform(function ($part) {
|
||||
unset($part['book_id']);
|
||||
$part['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $part['law_id'])->first()?->is_locked;
|
||||
$part['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $part['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($part['law_id']);
|
||||
|
||||
return $part;
|
||||
});
|
||||
|
||||
|
||||
return $this->success($parts->items());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\SubscribePlan;
|
||||
use App\Models\UserSubscriber;
|
||||
@@ -29,7 +28,7 @@ class PayController extends Controller
|
||||
$invoice = (new Invoice)->amount($subscribePlan->price);
|
||||
|
||||
$callback = 'https://ghaafapp.ir';
|
||||
$payment = Payment::callbackUrl($callback . '/payment/callback')
|
||||
$payment = Payment::callbackUrl($callback.'/payment/callback')
|
||||
->purchase($invoice, function ($driver, $transaction_id) use ($subscribePlan) {
|
||||
PaymentTransaction::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
@@ -43,7 +42,8 @@ class PayController extends Controller
|
||||
|
||||
return $this->success(['url' => $payment]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Payment initiation failed: ' . $e->getMessage());
|
||||
Log::error('Payment initiation failed: '.$e->getMessage());
|
||||
|
||||
return $this->failed('Payment initialization failed', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -78,20 +78,21 @@ class PayController extends Controller
|
||||
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
|
||||
} catch (\Exception $e) {
|
||||
Log::info('error in callback function', ['error' => $e->getMessage()]);
|
||||
|
||||
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function send($url, $api, $amount, $redirect, $factorId, $name, $email, $description)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&amount=$amount&redirect=$redirect&factorId=$factorId&name=$name&email=$email&description=$description");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -100,10 +101,11 @@ class PayController extends Controller
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&id_get=$id_get&trans_id=$trans_id&json=1");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SectionRequest;
|
||||
use App\Models\Law;
|
||||
use App\Models\LikeSection;
|
||||
use App\Models\Order;
|
||||
use App\Models\Section;
|
||||
use App\Traits\BaseApiResponse;
|
||||
|
||||
@@ -26,7 +25,7 @@ class SectionController extends Controller
|
||||
$section->getCollection()->transform(function ($section) {
|
||||
unset($section['book_id']);
|
||||
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked;
|
||||
|
||||
|
||||
unset($section['law_id']);
|
||||
|
||||
return $section;
|
||||
|
||||
@@ -30,6 +30,7 @@ class SubscribePlanController extends Controller
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $q->id,
|
||||
'name' => $q->name,
|
||||
@@ -37,7 +38,7 @@ class SubscribePlanController extends Controller
|
||||
'expired_day' => $q->expired_day,
|
||||
'is_free' => $q->is_free == 1 ? true : false,
|
||||
'type' => $q->type,
|
||||
'transaction' => $q->transaction
|
||||
'transaction' => $q->transaction,
|
||||
|
||||
];
|
||||
})->filter(function ($q) {
|
||||
@@ -60,7 +61,7 @@ class SubscribePlanController extends Controller
|
||||
->where('expired_at', '>', now())
|
||||
->first();
|
||||
|
||||
if ($activeSubscription && !$activeSubscription?->subscribe?->is_free && !$subscribePlan->is_free) {
|
||||
if ($activeSubscription && ! $activeSubscription?->subscribe?->is_free && ! $subscribePlan->is_free) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You already have an active subscription. Please wait until it expires.']);
|
||||
}
|
||||
|
||||
@@ -102,7 +103,8 @@ class SubscribePlanController extends Controller
|
||||
|
||||
return $this->success(['url' => $payment]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Payment initiation failed: ' . $e->getMessage());
|
||||
Log::error('Payment initiation failed: '.$e->getMessage());
|
||||
|
||||
return $this->failed(null, 'درگاه پرداخت در دسترس نیست');
|
||||
}
|
||||
}
|
||||
@@ -112,7 +114,7 @@ class SubscribePlanController extends Controller
|
||||
$request->validate([
|
||||
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
|
||||
'subscription_id' => 'nullable',
|
||||
'purchase_token' => 'nullable'
|
||||
'purchase_token' => 'nullable',
|
||||
]);
|
||||
|
||||
$subscribePlan = SubscribePlan::findOrFail($request->subscribe_plan_id);
|
||||
@@ -139,7 +141,7 @@ class SubscribePlanController extends Controller
|
||||
$user->userSubscribers()->create([
|
||||
'subscribe_plan_id' => $subscribePlan->id,
|
||||
'expired_at' => $expiredAt,
|
||||
'is_free' => true
|
||||
'is_free' => true,
|
||||
]);
|
||||
|
||||
return $this->success(null, 'Subscribe Plan', 'Free Subscribe Plan Successfully Activated');
|
||||
@@ -148,14 +150,14 @@ class SubscribePlanController extends Controller
|
||||
$subscription_id = $request->input('subscription_id');
|
||||
$purchase_token = $request->input('purchase_token');
|
||||
|
||||
if (!$subscription_id || !$purchase_token) {
|
||||
if (! $subscription_id || ! $purchase_token) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid subscription details.']);
|
||||
}
|
||||
|
||||
try {
|
||||
$bazaarExpiredAt = $this->marketVerifier->verifyBazaarSubscription($subscription_id, $purchase_token);
|
||||
|
||||
if (!$bazaarExpiredAt) {
|
||||
if (! $bazaarExpiredAt) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or expired subscription.']);
|
||||
}
|
||||
|
||||
@@ -172,12 +174,13 @@ class SubscribePlanController extends Controller
|
||||
'purchase_token' => $purchase_token,
|
||||
'market_provider' => 'bazaar',
|
||||
'last_verified_at' => now(),
|
||||
'is_free' => false
|
||||
'is_free' => false,
|
||||
]);
|
||||
|
||||
return $this->success(null, 'Subscribe Plan', 'Subscription successfully activated.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in subscription', ['Error' => $e->getMessage()]);
|
||||
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Failed to verify subscription.']);
|
||||
}
|
||||
}
|
||||
@@ -207,7 +210,7 @@ class SubscribePlanController extends Controller
|
||||
try {
|
||||
$purchase = $this->marketVerifier->verifyMyketProduct($request->sku_id, $token);
|
||||
|
||||
if (!$purchase) {
|
||||
if (! $purchase) {
|
||||
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or failed Myket purchase.']);
|
||||
}
|
||||
|
||||
@@ -306,16 +309,16 @@ class SubscribePlanController extends Controller
|
||||
return $this->success(null, 'Subscribe Plan', 'No Subscribe Plan');
|
||||
}
|
||||
|
||||
|
||||
private function send($url, $api, $amount, $redirect, $factorId, $name, $email, $description)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&amount=$amount&redirect=$redirect&factorId=$factorId&name=$name&email=$email&description=$description");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -324,10 +327,11 @@ class SubscribePlanController extends Controller
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&id_get=$id_get&trans_id=$trans_id&json=1");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@ class VersionController extends Controller
|
||||
{
|
||||
$version = Version::query()->where('type', $versionRequest->type)->orderBy('id', 'desc')->first();
|
||||
|
||||
if (!$version) {
|
||||
if (! $version) {
|
||||
return $this->failed([], 'Version not found');
|
||||
}
|
||||
|
||||
if (intval($version->number) > $versionRequest->number) {
|
||||
return $this->success([
|
||||
'force_update' => $version->force_update == 1 ? true : false
|
||||
'force_update' => $version->force_update == 1 ? true : false,
|
||||
], 'Your app need to be updated');
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'force_update' => false
|
||||
'force_update' => false,
|
||||
], 'Version successfully');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Models\Chapter;
|
||||
use App\Models\Division;
|
||||
use App\Models\Gate;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Models\Part;
|
||||
use App\Models\RecentArt;
|
||||
use App\Models\Section;
|
||||
@@ -35,7 +34,7 @@ class VolumController extends Controller
|
||||
|
||||
$volumes->getCollection()->transform(function ($volume) {
|
||||
$volume['has_book'] = Book::where('volum_id', $volume->id)->exists();
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $volume['law_id'])->first()?->is_locked;
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $volume['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($volume['law_id']);
|
||||
|
||||
@@ -63,7 +62,7 @@ class VolumController extends Controller
|
||||
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
||||
->find($bookId);
|
||||
|
||||
if (!$book) {
|
||||
if (! $book) {
|
||||
return $this->success([], 'Book not found');
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
$paginationData = [
|
||||
@@ -100,11 +99,10 @@ class VolumController extends Controller
|
||||
$division = Division::with(['sections', 'chapters', 'parts', 'gate', 'branch', 'art'])
|
||||
->find($division_id);
|
||||
|
||||
if (!$division) {
|
||||
if (! $division) {
|
||||
return $this->success([], 'Division not found');
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
$foundRelation = false;
|
||||
foreach (['sections', 'chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
|
||||
@@ -117,7 +115,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -135,7 +133,7 @@ class VolumController extends Controller
|
||||
$section = Section::with(['chapters', 'parts', 'gate', 'branch', 'art'])
|
||||
->find($section_id);
|
||||
|
||||
if (!$section) {
|
||||
if (! $section) {
|
||||
return $this->success([], 'Section not found');
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -168,7 +166,7 @@ class VolumController extends Controller
|
||||
if ($volumeId) {
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
||||
->find($volumeId);
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -184,7 +182,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -202,7 +200,7 @@ class VolumController extends Controller
|
||||
$part = Part::with(['gate', 'branch', 'art'])
|
||||
->find($part_id);
|
||||
|
||||
if (!$part) {
|
||||
if (! $part) {
|
||||
return $this->success([], 'Part not found');
|
||||
}
|
||||
|
||||
@@ -218,7 +216,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -236,7 +234,7 @@ class VolumController extends Controller
|
||||
$chapter = Chapter::with(['parts', 'gate', 'branch', 'art'])
|
||||
->find($chapter_id);
|
||||
|
||||
if (!$chapter) {
|
||||
if (! $chapter) {
|
||||
return $this->success([], 'Chapter not found');
|
||||
}
|
||||
|
||||
@@ -252,7 +250,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -270,7 +268,7 @@ class VolumController extends Controller
|
||||
$branch = Branch::with(['art'])
|
||||
->find($branch_id);
|
||||
|
||||
if (!$branch) {
|
||||
if (! $branch) {
|
||||
return $this->success([], 'Branch not found');
|
||||
}
|
||||
|
||||
@@ -286,7 +284,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -300,12 +298,11 @@ class VolumController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($gate_id) {
|
||||
$gate = Gate::with(['branch', 'art'])
|
||||
->find($gate_id);
|
||||
|
||||
if (!$gate) {
|
||||
if (! $gate) {
|
||||
return $this->success([], 'Gate not found');
|
||||
}
|
||||
|
||||
@@ -321,7 +318,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -339,7 +336,7 @@ class VolumController extends Controller
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs'])
|
||||
->find($volumeId);
|
||||
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -355,7 +352,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -372,7 +369,7 @@ class VolumController extends Controller
|
||||
if ($law_Id) {
|
||||
$law = Law::find($law_Id);
|
||||
|
||||
if (!$law) {
|
||||
if (! $law) {
|
||||
return $this->success([], 'Law not found');
|
||||
}
|
||||
|
||||
@@ -380,16 +377,14 @@ class VolumController extends Controller
|
||||
->where('law_id', $law->id)
|
||||
->get();
|
||||
|
||||
|
||||
RecentArt::query()->updateOrCreate([
|
||||
'user_id' => auth()->user()->id,
|
||||
'law_id' => $law_Id
|
||||
'law_id' => $law_Id,
|
||||
], [
|
||||
'user_id' => auth()->user()->id,
|
||||
'law_id' => $law_Id
|
||||
'law_id' => $law_Id,
|
||||
]);
|
||||
|
||||
|
||||
$data = [];
|
||||
|
||||
if (count($arts) > 0) {
|
||||
@@ -399,9 +394,10 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'volume',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success($data, 'Success');
|
||||
}
|
||||
|
||||
@@ -423,9 +419,10 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'art',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success($data, 'Success');
|
||||
}
|
||||
|
||||
@@ -504,8 +501,8 @@ class VolumController extends Controller
|
||||
'foreign_key' => 'branch_id',
|
||||
'type' => (new Art)->getTable(),
|
||||
'check_mode' => Art::class,
|
||||
'check_key' => 'branch_id'
|
||||
]
|
||||
'check_key' => 'branch_id',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($filters as $filterKey => $filterInfo) {
|
||||
@@ -533,7 +530,7 @@ class VolumController extends Controller
|
||||
'title' => $item?->title,
|
||||
'number' => $item?->number,
|
||||
'type' => $type,
|
||||
'is_end' => $check_model::where($check_key, $item?->id)->count() !== 0 ? false : true
|
||||
'is_end' => $check_model::where($check_key, $item?->id)->count() !== 0 ? false : true,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -544,7 +541,6 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No law or book or volume specified');
|
||||
}
|
||||
|
||||
|
||||
public function check_filter_with_art(CheckBookFilterRequest $request)
|
||||
{
|
||||
$lawId = $request->law_id;
|
||||
@@ -584,7 +580,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($lawId) {
|
||||
$law = Law::with(['volums', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'])->find($lawId);
|
||||
if (!$law) {
|
||||
if (! $law) {
|
||||
return $this->success([], 'Law not found');
|
||||
}
|
||||
|
||||
@@ -596,10 +592,9 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No related records found in the law');
|
||||
}
|
||||
|
||||
|
||||
if ($bookId) {
|
||||
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($bookId);
|
||||
if (!$book) {
|
||||
if (! $book) {
|
||||
return $this->success([], 'Book not found');
|
||||
}
|
||||
|
||||
@@ -613,7 +608,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($volumeId) {
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($volumeId);
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -627,7 +622,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($sectionId) {
|
||||
$section = Section::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($sectionId);
|
||||
if (!$section) {
|
||||
if (! $section) {
|
||||
return $this->success([], 'Section not found');
|
||||
}
|
||||
|
||||
@@ -641,7 +636,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($divisionId) {
|
||||
$division = Division::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($divisionId);
|
||||
if (!$division) {
|
||||
if (! $division) {
|
||||
return $this->success([], 'Division not found');
|
||||
}
|
||||
|
||||
@@ -655,7 +650,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($partId) {
|
||||
$part = Part::with(['gates', 'art'])->find($partId);
|
||||
if (!$part) {
|
||||
if (! $part) {
|
||||
return $this->success([], 'Part not found');
|
||||
}
|
||||
|
||||
@@ -669,7 +664,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($branchId) {
|
||||
$branch = Branch::with(['gates', 'chapters', 'art'])->find($branchId);
|
||||
if (!$branch) {
|
||||
if (! $branch) {
|
||||
return $this->success([], 'Branch not found');
|
||||
}
|
||||
|
||||
@@ -683,7 +678,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($chapterId) {
|
||||
$chapter = Chapter::with(['gate', 'parts', 'art'])->find($chapterId);
|
||||
if (!$chapter) {
|
||||
if (! $chapter) {
|
||||
return $this->success([], 'Chapter not found');
|
||||
}
|
||||
|
||||
@@ -697,7 +692,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($gateId) {
|
||||
$gate = Gate::with(['art'])->find($gateId);
|
||||
if (!$gate) {
|
||||
if (! $gate) {
|
||||
return $this->success([], 'Gate not found');
|
||||
}
|
||||
|
||||
@@ -712,7 +707,6 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No valid filter specified');
|
||||
}
|
||||
|
||||
|
||||
private function prepareItemsData($items, $type)
|
||||
{
|
||||
$data = [];
|
||||
@@ -724,14 +718,15 @@ class VolumController extends Controller
|
||||
'number' => $item->number,
|
||||
'type' => $type,
|
||||
'route' => $this->route($item, $item),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
'law' => $law?->title,
|
||||
'image' => $law?->image,
|
||||
'count_art' => $law?->arts?->count() ?? 0,
|
||||
'count_art' => $law?->arts?->count() ?? 0,
|
||||
'count_volums' => $law?->volums?->count() ?? 0,
|
||||
'price' => $law?->price,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -740,13 +735,14 @@ class VolumController extends Controller
|
||||
foreach ($relations as $relation) {
|
||||
if ($model->{$relation} && $model->{$relation}->count() > 0) {
|
||||
$items = $model->{$relation}()->paginate($perPage);
|
||||
|
||||
return $this->prepareItemsData($items, $relation);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private function convertValueTo($var)
|
||||
{
|
||||
switch ($var) {
|
||||
@@ -769,13 +765,13 @@ class VolumController extends Controller
|
||||
switch ((new $modelClass)->getTable()) {
|
||||
case 'laws':
|
||||
$route = array_filter([
|
||||
Law::find($query->id)?->title
|
||||
Law::find($query->id)?->title,
|
||||
]);
|
||||
break;
|
||||
case 'volums':
|
||||
$route = array_filter([
|
||||
Law::find($query->law_id)?->title,
|
||||
Volum::find($query->id)?->title
|
||||
Volum::find($query->id)?->title,
|
||||
]);
|
||||
break;
|
||||
case 'books':
|
||||
|
||||
Reference in New Issue
Block a user