restore composer.json, add mysqli extension
This commit is contained in:
48
app/Http/Controllers/Dashboard/AuthController.php
Executable file
48
app/Http/Controllers/Dashboard/AuthController.php
Executable file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Auth\LoginController as DefaultLoginController;
|
||||
|
||||
class AuthController extends DefaultLoginController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest:staff')->except('logout');
|
||||
}
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('login');
|
||||
}
|
||||
|
||||
protected function guard()
|
||||
{
|
||||
return Auth::guard('staff');
|
||||
}
|
||||
|
||||
public function username()
|
||||
{
|
||||
return 'username';
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$this->guard()->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
if ($response = $this->loggedOut($request)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $request->wantsJson()
|
||||
? new Response('', 204)
|
||||
: redirect('/');
|
||||
}
|
||||
}
|
||||
34
app/Http/Controllers/Dashboard/Billing/Controller.php
Executable file
34
app/Http/Controllers/Dashboard/Billing/Controller.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Billing;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Billing;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'billings');
|
||||
$billings = Billing::latest('id')
|
||||
->paginate(config(50));
|
||||
$currency = Currency::latest()->first();
|
||||
|
||||
return view('dashboard.billing.index', compact('billings', 'currency'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$id = $request->get('query');
|
||||
$billings = Billing::where('id', $id)->orWhere('transaction_id', $id)->paginate(50);
|
||||
|
||||
return view('dashboard.billing.index', compact('billings'));
|
||||
|
||||
}
|
||||
}
|
||||
59
app/Http/Controllers/Dashboard/Branch/Controller.php
Executable file
59
app/Http/Controllers/Dashboard/Branch/Controller.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Branch;
|
||||
|
||||
use App\Http\Controllers\Controller as BaseController;
|
||||
use App\Http\Requests\Dashboard\Branch\Request;
|
||||
use App\Jobs\Dashboard\Branch\Store;
|
||||
use App\Jobs\Dashboard\Branch\Update;
|
||||
use App\Models\Branch;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'branches');
|
||||
$branches = Branch::latest('id')->paginate(20);
|
||||
return view('dashboard.branches.index', compact('branches'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->isMethod('get'))
|
||||
{
|
||||
$this->authorize('create', 'branches');
|
||||
return view('dashboard.branches.create');
|
||||
}
|
||||
|
||||
$this->dispatchSync(new Store($request));
|
||||
$this->success(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.branches');
|
||||
}
|
||||
|
||||
public function show(Branch $branch)
|
||||
{
|
||||
$this->authorize('view', 'branches');
|
||||
return view('dashboard.branches.preview', compact('branch'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Branch $branch)
|
||||
{
|
||||
if ($request->isMethod('get'))
|
||||
{
|
||||
$this->authorize('update', 'branches');
|
||||
return view('dashboard.branches.edit', compact('branch'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(new Update($request, $branch));
|
||||
$this->success(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.branches');
|
||||
}
|
||||
|
||||
public function destroy(Branch $branch)
|
||||
{
|
||||
$this->authorize('delete', 'branches');
|
||||
$branch->delete();
|
||||
$this->success(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
152
app/Http/Controllers/Dashboard/Brand/Controller.php
Executable file
152
app/Http/Controllers/Dashboard/Brand/Controller.php
Executable file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Brand;
|
||||
|
||||
use App\Api\ImageResize;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Brand\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Brand\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Brand\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Brand\Update as UpdateJob;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $brands;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Brend $brand
|
||||
*/
|
||||
public function __construct(Brand $brand)
|
||||
{
|
||||
$this->brands = $brand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'brands');
|
||||
$brands = $this->brands->orderBy('position')->paginate(20);
|
||||
return view('dashboard.brands.index', compact('brands'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Brand $brand
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Brand $brand)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'brands');
|
||||
return view('dashboard.brands.update', compact('brand'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
// delete old image from s3
|
||||
Storage::disk('s3')->delete($brand->image);
|
||||
$path = $this->storeImageToS3($request->file('image'));
|
||||
} else {
|
||||
// detele old image
|
||||
if (is_file($brand->image)) {
|
||||
unlink($brand->image);
|
||||
}
|
||||
$path = $request->file('image')->store('uploads/brands');
|
||||
}
|
||||
} else {
|
||||
$path = $brand->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($brand, $request, $path));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.brands');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'brands');
|
||||
return view('dashboard.brands.store');
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$file = $request->file('image');
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$path = $this->storeImageToS3($file);
|
||||
} else {
|
||||
$path = $file->store('uploads/brands');
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.brands');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Brand $brand)
|
||||
{
|
||||
$this->authorize('delete', 'brands');
|
||||
|
||||
if (is_file($brand->image)) {
|
||||
unlink($brand->image);
|
||||
}
|
||||
|
||||
// delete image from s3
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
Storage::disk('s3')->delete($brand->image);
|
||||
}
|
||||
|
||||
Product::where('brand_id', $brand->id)->withTrashed()->update([
|
||||
'brand_id' => null
|
||||
]);
|
||||
|
||||
$brand->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
private function storeImageToS3($image): string
|
||||
{
|
||||
$path = '';
|
||||
|
||||
// first store temp file and resize it, then upload to s3
|
||||
// 1 - store temp file
|
||||
$tempPath = $image->store('temp', 'public');
|
||||
if ($tempPath) {
|
||||
$tempFilePath = storage_path('app/public/' . $tempPath);
|
||||
$image = new ImageResize();
|
||||
$path = $image->resize($tempPath, 322, 'brands');
|
||||
|
||||
// 2 - upload to s3 or keep local
|
||||
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
|
||||
Storage::disk('s3')->put($path, file_get_contents($path));
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
301
app/Http/Controllers/Dashboard/Category/Controller.php
Executable file
301
app/Http/Controllers/Dashboard/Category/Controller.php
Executable file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Category;
|
||||
|
||||
use App\Models\Brand;
|
||||
use App\Models\Category;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Category\Request as StoreRequest;
|
||||
use App\Http\Requests\Dashboard\Category\Update as UpdateRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Category\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Category\Update as UpdateJob;
|
||||
use App\Models\Characteristic;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'categories');
|
||||
$categories = Category::select('id', 'name->ru as category', 'position', 'parent_id')
|
||||
->where('parent_id', null)
|
||||
->with(['children' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id', 'position')->orderBy('position', 'asc')->with(['children' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id', 'position')->orderBy('position', 'asc');
|
||||
}]);
|
||||
}])->orderBy('position', 'asc')->get();
|
||||
|
||||
return view('dashboard.category.index', compact('categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('view', 'categories');
|
||||
|
||||
$brands = Brand::all();
|
||||
$brands->map(function ($brand) {
|
||||
$brand->name = $brand->name['ru'];
|
||||
});
|
||||
|
||||
$parent_categories = Category::with('parent')->get();
|
||||
return view('dashboard.category.store', compact('brands', 'parent_categories'));
|
||||
}
|
||||
|
||||
$category = $this->dispatchSync(new StoreJob($request));
|
||||
|
||||
if (!empty($request->char)) {
|
||||
foreach ($request->char as $char) {
|
||||
Characteristic::create([
|
||||
'name' => $char['name'],
|
||||
'type' => $char['type'],
|
||||
'category_id' => $category->id,
|
||||
'filter' => $char['filter'] == 'true' ? 1 : 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success(trans('admin.messages.created'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $category
|
||||
* @param UpdateRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update($category, UpdateRequest $request)
|
||||
{
|
||||
$category = Category::findOrFail($category);
|
||||
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'categories');
|
||||
$parent_categories = Category::with('parent')->whereNotIn('id', [$category->id])->get();
|
||||
$brands = Brand::all();
|
||||
|
||||
$brands->map(function ($brand) {
|
||||
$brand->name = $brand->name['ru'];
|
||||
});
|
||||
|
||||
$category->loadMissing(['brands', 'characteristics']);
|
||||
|
||||
$category->brands->map(function ($brand) {
|
||||
$brand->name = $brand->name['ru'];
|
||||
});
|
||||
|
||||
return view('dashboard.category.update', compact('parent_categories', 'category', 'brands'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image')->store('uploads/categories', 'local');
|
||||
} else {
|
||||
$image = $category->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(new UpdateJob($category, $request, $image));
|
||||
|
||||
if (!empty($request->char)) {
|
||||
foreach ($request->char as $char) {
|
||||
if ($char['id'] == null || $char['id'] == 'null') {
|
||||
Characteristic::create([
|
||||
'name' => $char['name'],
|
||||
'type' => $char['type'],
|
||||
'category_id' => $category->id,
|
||||
'filter' => $char['filter'] == 'true' ? 1 : 0
|
||||
]);
|
||||
} else {
|
||||
Characteristic::where('id', $char['id'])->update([
|
||||
'name' => $char['name'],
|
||||
'type' => $char['type'],
|
||||
'filter' => $char['filter'] == 'true' ? 1 : 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($request->deletes['char'])) {
|
||||
$chars = Characteristic::whereIn('id', $request->deletes['char'])->get();
|
||||
|
||||
foreach ($chars as $char) {
|
||||
$char->values()->detach();
|
||||
// foreach ($char->values as $value) {
|
||||
// $value->delete();
|
||||
// }
|
||||
$char->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$this->success(trans('admin.messages.updated'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete($category)
|
||||
{
|
||||
$this->authorize('delete', 'categories');
|
||||
$category = Category::findOrFail($category);
|
||||
|
||||
if (is_file($category->image)) {
|
||||
unlink($category->image);
|
||||
}
|
||||
|
||||
// delete image from s3
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
Storage::disk('s3')->delete($category->image);
|
||||
}
|
||||
|
||||
$category->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function position_save(Request $request)
|
||||
{
|
||||
foreach ($request->categories as $category) {
|
||||
$cat = Category::find($category['id']);
|
||||
$cat->parent_id = $category['parent_id'] === 'null' ? null : $category['parent_id'];
|
||||
$cat->position = $category['position'];
|
||||
$cat->save();
|
||||
if (!empty($category['children'])) {
|
||||
foreach ($category['children'] as $c) {
|
||||
$cc = Category::find($c['id']);
|
||||
$cc->parent_id = $c['parent_id'] === 'null' ? null : $c['parent_id'];
|
||||
$cc->position = $c['position'];
|
||||
$cc->save();
|
||||
|
||||
if (!empty($c['children'])) {
|
||||
foreach ($c['children'] as $ccc) {
|
||||
$cccc = Category::find($ccc['id']);
|
||||
$cccc->parent_id = $ccc['parent_id'] === 'null' ? null : $ccc['parent_id'];
|
||||
$cccc->position = $ccc['position'];
|
||||
$cccc->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$categories = Category::select('id', 'name->ru as category')
|
||||
->where('parent_id', null)
|
||||
->with('parents.parents.parents')->get();
|
||||
|
||||
$cat = $this->category($categories->toArray());
|
||||
$cats = array_merge(...$cat);
|
||||
|
||||
return $cats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $categories
|
||||
* @return array
|
||||
*/
|
||||
private function category($categories)
|
||||
{
|
||||
return array_map(function ($cat) {
|
||||
$arr = [];
|
||||
|
||||
if (count($cat['parents']) > 0) {
|
||||
$arr[] = [
|
||||
'id' => $cat['id'],
|
||||
'category' => $cat['name']['ru'],
|
||||
'$isDisabled' => true
|
||||
];
|
||||
|
||||
foreach ($cat['parents'] as $parent) {
|
||||
if (count($parent['parents']) > 0) {
|
||||
|
||||
if (count($parent['parents']) > 0) {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => true
|
||||
|
||||
];
|
||||
foreach ($parent['parents'] as $paren) {
|
||||
|
||||
$arr[] = [
|
||||
'id' => $paren['id'],
|
||||
'category' => $paren['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
} else {
|
||||
$arr = [
|
||||
'id' => $cat['id'],
|
||||
'category' => $cat['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
return $arr;
|
||||
}
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function json()
|
||||
{
|
||||
$categories = Category::select('id', 'name', 'parent_id as parrent', 'position', 'published')->latest('id')->get();
|
||||
$data = "data ='{$categories}';";
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
87
app/Http/Controllers/Dashboard/City/Controller.php
Executable file
87
app/Http/Controllers/Dashboard/City/Controller.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\City;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Region;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\City\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\City\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\City\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\City\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $cities;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param City $city
|
||||
*/
|
||||
public function __construct(City $city)
|
||||
{
|
||||
$this->cities = $city;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'cities');
|
||||
$cities = $this->cities->latest('id')->paginate(20);
|
||||
return view('dashboard.cities.index', compact('cities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param City $city
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function update(UpdateRequest $request, City $city)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'cities');
|
||||
$regions = Region::all();
|
||||
return view('dashboard.cities.update', compact('city', 'regions'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($city, $request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.cities');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'cities');
|
||||
$regions = Region::all();
|
||||
return view('dashboard.cities.store', compact('regions'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.cities');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param City $city
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(City $city)
|
||||
{
|
||||
$this->authorize('delete', 'cities');
|
||||
$city->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
54
app/Http/Controllers/Dashboard/Color/Controller.php
Executable file
54
app/Http/Controllers/Dashboard/Color/Controller.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Color;
|
||||
|
||||
use App\Http\Controllers\Controller as BaseController;
|
||||
use App\Http\Requests\Dashboard\Color\Request;
|
||||
use App\Jobs\Dashboard\Color\Store;
|
||||
use App\Jobs\Dashboard\Color\Update;
|
||||
use App\Models\Color;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'colors');
|
||||
$colors = Color::latest('id')->paginate(20);
|
||||
return view('dashboard.colors.index', compact('colors'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->isMethod('get'))
|
||||
{
|
||||
$this->authorize('create', 'categories');
|
||||
return view('dashboard.colors.create');
|
||||
}
|
||||
|
||||
$this->dispatchSync(new Store($request));
|
||||
$this->success(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.colors');
|
||||
}
|
||||
|
||||
public function update(Request $request, Color $color)
|
||||
{
|
||||
if ($request->isMethod('get'))
|
||||
{
|
||||
$this->authorize('update', 'categories');
|
||||
return view('dashboard.colors.update', compact('color'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(new Update($request, $color));
|
||||
$this->success(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.colors');
|
||||
}
|
||||
|
||||
public function destroy(Color $color)
|
||||
{
|
||||
$this->authorize('delete', 'categories');
|
||||
$color->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
71
app/Http/Controllers/Dashboard/Comment/Controller.php
Executable file
71
app/Http/Controllers/Dashboard/Comment/Controller.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Comment;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Comment\Update as UpdateRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Comment\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $comments;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Comment $comment
|
||||
*/
|
||||
public function __construct(Comment $comment)
|
||||
{
|
||||
$this->comments = $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'comments');
|
||||
$comments = $this->comments->with('product')
|
||||
->latest('id')->paginate(20);
|
||||
|
||||
return view('dashboard.comments.index', compact('comments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function update(Comment $comment)
|
||||
{
|
||||
$this->authorize('update', 'comments');
|
||||
return view('dashboard.comments.edit', compact('comment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Comment $comment)
|
||||
{
|
||||
$this->authorize('delete', 'comments');
|
||||
$comment->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function publish(Comment $comment)
|
||||
{
|
||||
$this->authorize('update', 'comments');
|
||||
$comment->update([
|
||||
'publish' => true
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.published'));
|
||||
return redirect()->route('dashboard.comments');
|
||||
}
|
||||
}
|
||||
65
app/Http/Controllers/Dashboard/Company/CompanyController.php
Executable file
65
app/Http/Controllers/Dashboard/Company/CompanyController.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Company;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Company;
|
||||
|
||||
class CompanyController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$company = Company::first();
|
||||
return view('dashboard.company.index', compact('company'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $companyId)
|
||||
{
|
||||
$company = Company::findOrFail($companyId);
|
||||
|
||||
$this->validate($request, [
|
||||
'company_name.uz' => 'required|string',
|
||||
'company_name.ru' => 'required|string',
|
||||
'inn' => 'required|string',
|
||||
'bank_name.uz' => 'required|string',
|
||||
'bank_name.ru' => 'required|string',
|
||||
'mfo' => 'required|string',
|
||||
'oked' => 'required|string',
|
||||
'address' => 'required|array',
|
||||
'address.uz' => 'required|string',
|
||||
'address.ru' => 'required|string',
|
||||
'director_full_name.uz' => 'required|string',
|
||||
'director_full_name.ru' => 'required|string',
|
||||
'payment_account' => 'required|string',
|
||||
'phone' => 'required|string',
|
||||
]);
|
||||
|
||||
$company->update([
|
||||
'company_name' => [
|
||||
"uz" => $request->company_name['uz'],
|
||||
"ru" => $request->company_name['ru'],
|
||||
],
|
||||
'inn' => $request->inn,
|
||||
'bank_name' => [
|
||||
"uz" => $request->bank_name['uz'],
|
||||
"ru" => $request->bank_name['ru'],
|
||||
],
|
||||
'mfo' => $request->mfo,
|
||||
'oked' => $request->oked,
|
||||
'address' => [
|
||||
'uz' => $request->address['uz'],
|
||||
'ru' => $request->address['ru']
|
||||
],
|
||||
'director_full_name' => [
|
||||
"uz" => $request->director_full_name['uz'],
|
||||
"ru" => $request->director_full_name['ru'],
|
||||
],
|
||||
'payment_account' => $request->payment_account,
|
||||
'phone' => $request->phone,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.companies.index');
|
||||
}
|
||||
}
|
||||
136
app/Http/Controllers/Dashboard/Compilation/Controller.php
Executable file
136
app/Http/Controllers/Dashboard/Compilation/Controller.php
Executable file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Compilation;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Category;
|
||||
use App\Models\Compilation;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Requests\Dashboard\Compilation\Store as StoreRequest;
|
||||
use App\Http\Requests\Dashboard\Compilation\Update as UpdateRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Compilation\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Compilation\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $products;
|
||||
protected $compilation;
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Product $product
|
||||
* @param Compilation $compilation
|
||||
* @param Category $category
|
||||
*/
|
||||
public function __construct(Product $product, Compilation $compilation, Category $category)
|
||||
{
|
||||
$this->products = $product;
|
||||
$this->compilation = $compilation;
|
||||
$this->categories = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'compilations');
|
||||
$compilations = Compilation::orderBy('position', 'asc')->get();
|
||||
return view('dashboard.compilations.index', compact('compilations'));
|
||||
}
|
||||
|
||||
// public function store(StoreRequest $request)
|
||||
// {
|
||||
// if ($request->isMethod('get')) {
|
||||
// $this->authorize('create', 'compilations');
|
||||
//
|
||||
//// $this->authorize('content-manager');
|
||||
// $categories = $this->categories->where('parent_id', null)->get();
|
||||
// return view('dashboard.compilations.store', compact('categories'));
|
||||
// }
|
||||
//
|
||||
// $this->dispatchSync(new StoreJob($request));
|
||||
//
|
||||
// $this->success(trans('admin.messages.created'));
|
||||
// return response()->json([
|
||||
// 'status' => true
|
||||
// ]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param Compilation $compilation
|
||||
* @param UpdateRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(Compilation $compilation, UpdateRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
// $this->authorize('content-manager');
|
||||
|
||||
$compilation->loadMissing(['products:id,name,poster']);
|
||||
|
||||
$this->authorize('update', 'compilations');
|
||||
|
||||
foreach ($compilation->products as $product) {
|
||||
$product->poster = '/'. $product->poster;
|
||||
$product->name = $product->name['ru'];
|
||||
}
|
||||
|
||||
|
||||
$categories = $this->categories->where('parent_id', false)->get();
|
||||
|
||||
|
||||
return view('dashboard.compilations.update', compact('compilation', 'categories'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(new UpdateJob($request, $compilation));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$query = $request->name;
|
||||
|
||||
$product = $this->products->published()->where('name->ru', 'like', $query . '%')->get()->map(function ($product) {
|
||||
return [
|
||||
'id' => $product->id,
|
||||
'poster' => '/' . $product->poster,
|
||||
'name' => $product->name['ru']
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'products' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Compilation $compilation
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Compilation $compilation)
|
||||
{
|
||||
$this->authorize('delete', 'compilations');
|
||||
$compilation->delete();
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
106
app/Http/Controllers/Dashboard/ContractTemplate/ContractTemplateController.php
Executable file
106
app/Http/Controllers/Dashboard/ContractTemplate/ContractTemplateController.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\ContractTemplate;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ContractTemplate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ContractTemplateController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$templates = ContractTemplate::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.contract-templates.index', compact('templates'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('dashboard.contract-templates.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'lang' => 'required|in:uz,ru',
|
||||
'type' => 'required|in:legal,physical',
|
||||
'file' => 'required|file|mimes:doc,docx',
|
||||
'company' => 'required|in:getgreen,sunhightech',
|
||||
]);
|
||||
|
||||
$folder = "contract-templates";
|
||||
$fileName = $request->file('file')->store($folder);
|
||||
|
||||
ContractTemplate::create([
|
||||
'lang' => $request->lang,
|
||||
'type' => $request->type,
|
||||
'company' => $request->company,
|
||||
'path' => $fileName,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.contract-templates.index');
|
||||
}
|
||||
|
||||
public function edit($templateId)
|
||||
{
|
||||
$template = ContractTemplate::findOrFail($templateId);
|
||||
return view('dashboard.contract-templates.edit', compact('template'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $templateId)
|
||||
{
|
||||
$template = ContractTemplate::findOrFail($templateId);
|
||||
|
||||
$this->validate($request, [
|
||||
'file' => 'nullable|file|mimes:doc,docx',
|
||||
'lang' => 'required|in:uz,ru',
|
||||
'company' => 'required|in:getgreen,sunhightech',
|
||||
'type' => 'required|in:legal,physical',
|
||||
]);
|
||||
|
||||
$template->update([
|
||||
'lang' => $request->lang,
|
||||
'company' => $request->company,
|
||||
'type' => $request->type,
|
||||
]);
|
||||
|
||||
if ($request->hasFile('file')) {
|
||||
// delete old file
|
||||
if ($template->path) {
|
||||
Storage::disk('public')->delete($template->path);
|
||||
}
|
||||
|
||||
// store file to storage
|
||||
$file = $request->file('file');
|
||||
// with generated name
|
||||
// generate name with 20 string
|
||||
$fileName = Str::random(20) . '.' . $file->extension();
|
||||
$file->storeAs('contract-templates', $fileName, 's3');
|
||||
|
||||
$template->update([
|
||||
'path' => 'contract-templates/' . $fileName,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.contract-templates.index');
|
||||
}
|
||||
|
||||
public function destroy($templateId)
|
||||
{
|
||||
$template = ContractTemplate::findOrFail($templateId);
|
||||
|
||||
if ($template->path) {
|
||||
Storage::disk('public')->delete($template->path);
|
||||
}
|
||||
|
||||
$template->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
235
app/Http/Controllers/Dashboard/Controller.php
Executable file
235
app/Http/Controllers/Dashboard/Controller.php
Executable file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Services\Dashboard\Stat\StatService;
|
||||
use App\Models\User;
|
||||
use App\Models\Order;
|
||||
use App\Models\Billing;
|
||||
use App\Models\Product;
|
||||
use App\Helpers\DashboardStatic;
|
||||
use Akaunting\Apexcharts\Chart;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$daysToShow = 30;
|
||||
$from = $request->get('from');
|
||||
$to = $request->get('to');
|
||||
|
||||
if (!$to) {
|
||||
$to = now()->format('Y-m-d');
|
||||
}
|
||||
|
||||
if (!$from) {
|
||||
$from = now()->subDays($daysToShow)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$service = new StatService();
|
||||
|
||||
// Create a new chart instance
|
||||
$chart = new Chart();
|
||||
|
||||
// Set the chart type to 'line'
|
||||
$chart->setType('line');
|
||||
|
||||
// Define the X-axis labels (months, dates, etc.)
|
||||
$chart->setLabels($service->getLabels($from, $to));
|
||||
|
||||
// Add a dataset to the chart (e.g., sales data)
|
||||
$chart->setDataset('Orders', 'line', $service->getStatics('orders'));
|
||||
$chart->setDataset('Users', 'line', $service->getStatics('users'));
|
||||
$chart->setDataset('Sales', 'line', $service->getStatics('sales'));
|
||||
|
||||
$users = User::count();
|
||||
$orders = Order::where('payment_type', '!=', 'credit')->count();
|
||||
$products = Product::where('child_id', null)->count();
|
||||
$billing = Billing::where('status', 'payed')->count();
|
||||
|
||||
$statics = [
|
||||
'labels' => $this->getLabels(),
|
||||
'orders_count' => $this->getStatics(),
|
||||
'new_users' => $this->getUserStatics(),
|
||||
'transactions' => $this->getCountTransactions(),
|
||||
'sum' => $this->getAllSumStatic(),
|
||||
];
|
||||
|
||||
return view('dashboard.index', compact(
|
||||
'users',
|
||||
'orders',
|
||||
'products',
|
||||
'billing',
|
||||
'statics',
|
||||
'chart'
|
||||
));
|
||||
}
|
||||
|
||||
private function getLabels()
|
||||
{
|
||||
$start = now()->subDays(30);
|
||||
$days = [];
|
||||
for ($i = 0; $i <= 30; $i++) {
|
||||
$days[] = $start->copy()->addDays($i)->format('d.m');
|
||||
}
|
||||
return $days;
|
||||
}
|
||||
|
||||
private function getUserStatics()
|
||||
{
|
||||
$users = DashboardStatic::getUserStatics();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'Пользователи',
|
||||
'values' => $users
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function changeLang($lang)
|
||||
{
|
||||
// validate
|
||||
if (!in_array($lang, ['en', 'ru', 'uz'])) {
|
||||
return response()->json([
|
||||
'message' => 'Language not supported'
|
||||
], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
session()->put('locale', $lang);
|
||||
App::setLocale($lang);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
private function getStatics()
|
||||
{
|
||||
$processing = DashboardStatic::getCountProcessing();
|
||||
$collect = DashboardStatic::getCountCollected();
|
||||
$waiting = DashboardStatic::getCountInWay();
|
||||
$closed = DashboardStatic::getCountClosed();
|
||||
$cancelled = DashboardStatic::getCountCancelled();
|
||||
$replacement = DashboardStatic::getCountReplacement();
|
||||
$archived = DashboardStatic::getCountArchived();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'В обработке',
|
||||
'values' => $processing
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Собран',
|
||||
'values' => $collect
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Ожидает',
|
||||
'values' => $waiting
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Закрыт',
|
||||
'values' => $closed
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Отменен',
|
||||
'values' => $cancelled
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Замена',
|
||||
'values' => $replacement
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Архиве',
|
||||
'values' => $archived
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getCountTransactions()
|
||||
{
|
||||
$payed = DashboardStatic::getSuccessTransactions();
|
||||
$waiting = DashboardStatic::getWaitingTransactions();
|
||||
$refused = DashboardStatic::getRefusedTransactions();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'Оплачено',
|
||||
'values' => $payed
|
||||
],
|
||||
[
|
||||
'name' => 'В ожидания',
|
||||
'values' => $waiting
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Отказано',
|
||||
'values' => $refused
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getCountCredit()
|
||||
{
|
||||
$payed = DashboardStatic::getCreditPayed();
|
||||
$cancelled = DashboardStatic::getCancelledCredit();
|
||||
$review = DashboardStatic::getReviewCredit();
|
||||
$waiting = DashboardStatic::getWaitingCredit();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'Оплачено',
|
||||
'values' => $payed
|
||||
],
|
||||
[
|
||||
'name' => 'Отказано',
|
||||
'values' => $cancelled
|
||||
],
|
||||
[
|
||||
'name' => 'Рассмотрение',
|
||||
'values' => $review
|
||||
],
|
||||
[
|
||||
'name' => 'В ожидание',
|
||||
'values' => $waiting
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getAllSumStatic()
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'Оплачено',
|
||||
'values' => []
|
||||
],
|
||||
[
|
||||
'name' => 'Не оплачено',
|
||||
'values' => []
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'Отказано',
|
||||
'values' => []
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
52
app/Http/Controllers/Dashboard/Currency/Controller.php
Executable file
52
app/Http/Controllers/Dashboard/Currency/Controller.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Currency;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Requests\Dashboard\Currency\Store as StoreRequest;
|
||||
use App\Jobs\Dashboard\Currency\Store as StoreJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Currency $currency
|
||||
*/
|
||||
public function __construct(Currency $currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'currencies');
|
||||
$currencies = $this->currency->latest('id')->limit(20)->get();
|
||||
return view('dashboard.currency.index', compact('currencies'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'compilations');
|
||||
return view('dashboard.currency.store');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request));
|
||||
$this->success(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->route('dashboard.currency');
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Http/Controllers/Dashboard/Feedback/Controller.php
Executable file
40
app/Http/Controllers/Dashboard/Feedback/Controller.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Feedback;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Feedback;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'feedback');
|
||||
$feedbacks = Feedback::latest('id')
|
||||
->paginate(15);
|
||||
|
||||
return view('dashboard.feedback.index', compact('feedbacks'));
|
||||
}
|
||||
|
||||
public function show(Feedback $feedback)
|
||||
{
|
||||
$this->authorize('update', 'feedback');
|
||||
|
||||
$feedback->update([
|
||||
'viewed' => true
|
||||
]);
|
||||
|
||||
return view('dashboard.feedback.show', compact('feedback'));
|
||||
}
|
||||
|
||||
public function destroy(Feedback $feedback)
|
||||
{
|
||||
$this->authorize('delete', 'feedback');
|
||||
|
||||
$feedback->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
72
app/Http/Controllers/Dashboard/File/Controller.php
Executable file
72
app/Http/Controllers/Dashboard/File/Controller.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\File;
|
||||
|
||||
use App\Models\File;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\File\Store as StoreRequest;
|
||||
use App\Jobs\Dashboard\File\Store as StoreJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param File $file
|
||||
*/
|
||||
public function __construct(File $file)
|
||||
{
|
||||
$this->files = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'files');
|
||||
|
||||
$files = $this->files->latest('id')->paginate(20);
|
||||
return view('dashboard.files.index', compact('files'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
$this->authorize('create', 'files');
|
||||
|
||||
$path = $request->file('file')->store('uploads/files');
|
||||
$size = filesize($path);
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path, $size));
|
||||
|
||||
$this->success(trans('admin.messages.updated'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param File $file
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(File $file)
|
||||
{
|
||||
$this->authorize('delete', 'files');
|
||||
|
||||
if (is_file($file->path)) {
|
||||
unlink($file->path);
|
||||
}
|
||||
|
||||
$file->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
60
app/Http/Controllers/Dashboard/Log/Controller.php
Executable file
60
app/Http/Controllers/Dashboard/Log/Controller.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Log;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Product;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', 'logs');
|
||||
|
||||
$date_from = $request->date_from;
|
||||
$description = $request->description;
|
||||
$user_id = $request->user_id;
|
||||
$log_name = $request->log_name;
|
||||
$id = $request->subject_id;
|
||||
|
||||
$logs = Activity::where('causer_type', 'App\Models\Staff')
|
||||
->with(['causer'])
|
||||
->whereNotIn('log_name', ['sliders', 'billings'])
|
||||
// ->whereHasMorph('subject', '*', function ($query, $type) {
|
||||
// Log::info($type);
|
||||
// if ($type === Product::class) {
|
||||
// return $query->where('price', '>', 0);
|
||||
// }
|
||||
// })
|
||||
->latest('id');
|
||||
|
||||
if (!is_null($date_from)) {
|
||||
$date_from = Carbon::parse($date_from)->format('Y-m-d 00:00:01');
|
||||
|
||||
$date_to = Carbon::now()->format('Y-m-d 23:59:59');
|
||||
|
||||
$logs = $logs->whereBetween('created_at', [$date_from, $date_to]);
|
||||
}
|
||||
|
||||
if (!is_null($description))
|
||||
$logs = $logs->where('description', $description);
|
||||
|
||||
if (!is_null($user_id))
|
||||
$logs = $logs->where('causer_id', $user_id);
|
||||
|
||||
if (!is_null($log_name))
|
||||
$logs = $logs->where('log_name', $log_name);
|
||||
|
||||
if (!is_null($id))
|
||||
$logs = $logs->where('subject_id', $id);
|
||||
|
||||
$logs = $logs->paginate(50);
|
||||
|
||||
return view('dashboard.logs.index', compact('logs'));
|
||||
}
|
||||
}
|
||||
83
app/Http/Controllers/Dashboard/Measurement/MeasurementController.php
Executable file
83
app/Http/Controllers/Dashboard/Measurement/MeasurementController.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Measurement;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Measurement;
|
||||
|
||||
class MeasurementController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// $this->authorize('view', 'measurements');
|
||||
|
||||
$measurements = Measurement::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.measurements.index', compact('measurements'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
// $this->authorize('create', 'measurements');
|
||||
|
||||
return view('dashboard.measurements.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// $this->authorize('create', 'measurements');
|
||||
|
||||
$this->validate($request, [
|
||||
'name_uz' => 'required|string|max:255',
|
||||
'name_ru' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
Measurement::create([
|
||||
'name' => [
|
||||
'uz' => $request->name_uz,
|
||||
'ru' => $request->name_ru,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.measurements.index');
|
||||
}
|
||||
|
||||
public function edit(Measurement $measurement)
|
||||
{
|
||||
// $this->authorize('update', 'measurements');
|
||||
|
||||
return view('dashboard.measurements.edit', compact('measurement'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Measurement $measurement)
|
||||
{
|
||||
// $this->authorize('update', 'measurements');
|
||||
|
||||
$this->validate($request, [
|
||||
'name_uz' => 'required|string|max:255',
|
||||
'name_ru' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$measurement->update([
|
||||
'name' => [
|
||||
'uz' => $request->name_uz,
|
||||
'ru' => $request->name_ru,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.measurements.index');
|
||||
}
|
||||
|
||||
public function destroy(Measurement $measurement)
|
||||
{
|
||||
// $this->authorize('delete', 'measurements');
|
||||
|
||||
$measurement->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
76
app/Http/Controllers/Dashboard/Notification/Controller.php
Executable file
76
app/Http/Controllers/Dashboard/Notification/Controller.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Notification;
|
||||
|
||||
use App\Models\Notification;
|
||||
use App\Models\NotificationAvailable;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Api\Firebase;
|
||||
//use App\Models\Firebase as Model;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Services\Dashboard\Notification\NotificationService;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $firebase;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->firebase = new Firebase();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$notifications = Notification::latest('id')->paginate(20);
|
||||
return view('dashboard.notifications.index', compact('notifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$lang = $request->lang;
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'body' => 'required',
|
||||
'lang' => 'required|in:uz,ru',
|
||||
]);
|
||||
|
||||
Notification::create([
|
||||
'title' => $request->title,
|
||||
'body' => $request->body,
|
||||
'language' => $request->lang
|
||||
]);
|
||||
|
||||
// Example usage
|
||||
$topic = $request->lang; // Topic name (you need all devices to subscribe to this topic)
|
||||
$title = $request->title;
|
||||
$body = $request->body;
|
||||
|
||||
// Send notification to multiple devices
|
||||
$service = new NotificationService();
|
||||
$response = $service->sendNotificationToTopic($topic, $title, $body);
|
||||
|
||||
// Output response
|
||||
dd($response);
|
||||
|
||||
return redirect()->back()->with(trans('admin.messages.created'));
|
||||
}
|
||||
|
||||
public function notification_available()
|
||||
{
|
||||
$notifications = NotificationAvailable::groupBy('product_id')->select('product_id')->with('product')->selectRaw('count(id) as count')->get();
|
||||
|
||||
return view('dashboard.notifications.alertNotification', compact('notifications'));
|
||||
}
|
||||
|
||||
public function notification_available_view($id)
|
||||
{
|
||||
$notifications = NotificationAvailable::where('product_id', $id)->get();
|
||||
|
||||
return view('dashboard.notifications.alertView', compact('notifications'));
|
||||
}
|
||||
}
|
||||
456
app/Http/Controllers/Dashboard/Orders/Controller.php
Executable file
456
app/Http/Controllers/Dashboard/Orders/Controller.php
Executable file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Orders;
|
||||
|
||||
use App\Api\Sms;
|
||||
use App\Exports\OrdersExport;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Currency;
|
||||
use App\Models\OrdersComment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderProducts;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Jobs\Dashboard\Order\Update as UpdateJob;
|
||||
use App\Jobs\Dashboard\Order\Products as ProductsUpdateJob;
|
||||
|
||||
use App\Http\Requests\Dashboard\Order\Update as UpdateRequest;
|
||||
|
||||
use PDF;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Http\Controllers\Apelsin\Controller as ApelsinController;
|
||||
use App\Services\Dashboard\Order\OrderFilterService;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $orders;
|
||||
protected $order_products;
|
||||
protected $products;
|
||||
protected $currency;
|
||||
protected $sms;
|
||||
protected $apelsin;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Order $order
|
||||
* @param OrderProducts $order_products
|
||||
* @param Product $product
|
||||
* @param Currency $currency
|
||||
*/
|
||||
public function __construct(Order $order, OrderProducts $order_products, Product $product, Currency $currency)
|
||||
{
|
||||
$this->orders = $order;
|
||||
$this->products = $product;
|
||||
$this->order_products = $order_products;
|
||||
$this->sms = new Sms();
|
||||
$this->currency = $currency->latest('id', 'desc')->limit(1)->first();
|
||||
$this->apelsin = new ApelsinController();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'orders');
|
||||
$orders = $this->orders->latest('id')->where('archived', false);
|
||||
|
||||
$statuses = [];
|
||||
|
||||
$permissions = auth()->user()->role->permissions;
|
||||
|
||||
if (!empty($permissions['order_status']['processing']) || !empty($permissions['order_status']['collected']) || !empty($permissions['order_status']['cancelled'])) {
|
||||
$statuses[] = 'processing';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['collected']) || !empty($permissions['order_status']['waiting_buyer']) || !empty($permissions['order_status']['in_way']) || !empty($permissions['order_status']['cancelled'])) {
|
||||
$statuses[] = 'collected';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['waiting_buyer']) || !empty($permissions['order_status']['closed']) || !empty($permissions['order_status']['cancelled'])) {
|
||||
$statuses[] = 'waiting_buyer';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['in_way']) || !empty($permissions['order_status']['closed']) || !empty($permissions['order_status']['cancelled'])) {
|
||||
$statuses[] = 'in_way';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['closed']) || !empty($permissions['order_status']['cancelled']) || !empty($permissions['order_status']['replacement'])) {
|
||||
$statuses[] = 'closed';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['cancelled'])) {
|
||||
$statuses[] = 'cancelled';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['replacement'])) {
|
||||
$statuses[] = 'replacement';
|
||||
}
|
||||
|
||||
if (!empty($permissions['order_status']['completed'])) {
|
||||
$statuses[] = 'completed';
|
||||
}
|
||||
|
||||
// $orders = $orders->whereIn('status', $statuses)->paginate(20);
|
||||
$orders = $orders->paginate(20);
|
||||
|
||||
return view('dashboard.orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function view(Order $order)
|
||||
{
|
||||
$this->authorize('view', 'orders');
|
||||
$products = $this->order_products->where('order_id', $order->id)->get();
|
||||
//total = $this->order_products->getTotalPrice($order->id);
|
||||
// $comments = OrdersComment::
|
||||
$logs = Activity::orderBy('id', 'asc')->where('subject_type', 'App\Models\Order')->where('subject_id', $order->id)->get();
|
||||
|
||||
$setting = Setting::find(1);
|
||||
return view('dashboard.orders.view', compact('order', 'products', 'setting', 'logs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function invoice_print(Order $order)
|
||||
{
|
||||
return view('invoice', compact('order'));
|
||||
// $path = public_path().'/pdf';
|
||||
// $pdf = PDF::loadView('invoice');
|
||||
// return $pdf->download('medium.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$orders = $this->orders->latest('id')->where('id', $request->get('id'))->paginate(20);
|
||||
return view('dashboard.orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function archive($order_id)
|
||||
{
|
||||
$order = Order::findOrFail($order_id);
|
||||
$order->archived = !$order->archived;
|
||||
$order->save();
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function mass_archived(Request $request)
|
||||
{
|
||||
switch ($request->input('action')) {
|
||||
case "unarchive":
|
||||
Order::whereIn('id', $request->order_id)->update([
|
||||
'archived' => false
|
||||
]);
|
||||
break;
|
||||
case "archived":
|
||||
Order::whereIn('id', $request->order_id)->update([
|
||||
'archived' => true
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->info('Успешно перенесен в архив');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
* @param UpdateRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(Order $order, UpdateRequest $request)
|
||||
{
|
||||
$branches = Branch::all();
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'orders');
|
||||
$order->loadMissing([
|
||||
'address.city.region',
|
||||
'products' => function ($product) {
|
||||
return $product->select('order_id', 'product_id', 'count', 'color_id', 'size', 'discount')->with([
|
||||
'product' => function ($product) {
|
||||
return $product->select('id', 'name', 'price', 'price_discount', 'poster_thumb', 'color_id', 'currency');
|
||||
},
|
||||
'color' => function ($color) {
|
||||
return $color->select('id', 'sizes', 'color_id')->with([
|
||||
'color'
|
||||
]);
|
||||
}
|
||||
]);
|
||||
},
|
||||
'branch:id,name'
|
||||
]);
|
||||
|
||||
foreach ($order->products as $product) {
|
||||
$product->product->price = $product->product->getPrice();
|
||||
$product->price_discount = $product->product->price_discount == null ? null : $product->product->getDiscountPrice();
|
||||
}
|
||||
|
||||
return view('dashboard.orders.update', compact('order', 'branches'));
|
||||
}
|
||||
|
||||
//$address = Address::find($order->address_id);
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($order, $request));
|
||||
//$this->dispatchSync(AddressUpdateJob::fromRequest($address, $request));
|
||||
$this->dispatchSync(new ProductsUpdateJob($order, $request));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function product(Product $product)
|
||||
{
|
||||
$product->loadMissing([
|
||||
'childrens' => function ($child) {
|
||||
return $child->select('id', 'child_id', 'color_id', 'sizes')->with([
|
||||
'color'
|
||||
]);
|
||||
}
|
||||
]);
|
||||
|
||||
$product->makeHidden([
|
||||
'body',
|
||||
'name',
|
||||
'brand_id',
|
||||
'child_id',
|
||||
'slug',
|
||||
'published',
|
||||
'updated_at',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
'poster',
|
||||
'poster_thumb',
|
||||
'price',
|
||||
'price_discount'
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'product' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function search_update(Request $request)
|
||||
{
|
||||
$query = $request->name;
|
||||
|
||||
$product = $this->products->where('name->ru', 'like', '%' . $query . '%')->isAvailable()->get()->map(function ($product) {
|
||||
return [
|
||||
'id' => $product->id,
|
||||
'poster' => '/' . $product->poster,
|
||||
'name' => $product->name['ru']
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'products' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function product_info(Product $product)
|
||||
{
|
||||
$this->authorize('view', 'orders');
|
||||
// if ($product->currency == 'dollar') {
|
||||
// $product->price = round($product->price * $this->currency->dollar, -3);
|
||||
// $product->price_discount = $product->price_discount == null ? null : round($product->price_discount * $this->currency->dollar, -3);
|
||||
// } else {
|
||||
// $product->price = round($product->price * $this->currency->euro, -3);
|
||||
// $product->price_discount = $product->price_discount == null ? null : round($product->price_discount * $this->currency->euro, -3);
|
||||
// }
|
||||
|
||||
$product->price = $product->getPrice();
|
||||
$product->price_discount = $product->price_discount == null ? null : $product->getDiscountPrice();
|
||||
|
||||
$product->loadMissing('childrens');
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'product' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
* @param $status
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function change_status(Order $order, $status)
|
||||
{
|
||||
$order->status = $status;
|
||||
$order->save();
|
||||
|
||||
$message = 'Order ' . $order->id . ' status changed to' . $status;
|
||||
|
||||
$this->sms->send($order->user->phone, $message);
|
||||
$order->save();
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function changePaymentStatus(Order $order, $status)
|
||||
{
|
||||
$order->payment_status = $status;
|
||||
$order->save();
|
||||
|
||||
$message = 'Order ' . $order->id . ' payment status changed to' . $status;
|
||||
|
||||
$this->sms->send($order->user->phone, $message);
|
||||
$order->save();
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function filter(Request $request)
|
||||
{
|
||||
$filterService = new OrderFilterService($request);
|
||||
$orders = $filterService->filter();
|
||||
return view('dashboard.orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function comments(Request $request)
|
||||
{
|
||||
$order = Order::find($request->order_id);
|
||||
|
||||
switch ($request->type) {
|
||||
case 'cancelled':
|
||||
if (!empty(auth()->user()->role->permissions['order_status']['cancelled'])) {
|
||||
$order->status = 'cancelled';
|
||||
foreach ($order->products as $row) {
|
||||
$product = Product::find($row->product_id);
|
||||
if (!empty($product)) {
|
||||
$product->count = $product->count + $row->count;
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
$message = "Quyoshli vash zakaz: {$order->id} otmenen!";
|
||||
} else {
|
||||
return abort(403, 'Мы от тебя не ждали :(');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replacement':
|
||||
if (!empty(auth()->user()->role->permissions['order_status']['replacement'])) {
|
||||
$order->status = 'replacement';
|
||||
} else {
|
||||
return abort(403, 'Мы от тебя не ждали :(');
|
||||
}
|
||||
break;
|
||||
case 'closed':
|
||||
if (!empty(auth()->user()->role->permissions['order_status']['closed']) || !empty(auth()->user()->role->permissions['order_status']['cancelled']) || !empty(auth()->user()->role->permissions['order_status']['replacement'])) {
|
||||
$order->status = 'closed';
|
||||
|
||||
if ($order->payment_type == 'credit') {
|
||||
$apelsin = $this->apelsin->delivered($order->id);
|
||||
|
||||
$order->update([
|
||||
'apelsin_data' => $apelsin
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$message = "Quyoshli vash zakaz: {$order->id} zavershen!";
|
||||
} else {
|
||||
return abort(403, 'Мы от тебя не ждали :(');
|
||||
}
|
||||
break;
|
||||
case 'completed':
|
||||
if (!empty(auth()->user()->role->permissions['order_status']['completed'])) {
|
||||
$order->status = 'completed';
|
||||
|
||||
if ($order->payment_type == 'credit') {
|
||||
$apelsin = $this->apelsin->delivered($order->id);
|
||||
|
||||
$order->update([
|
||||
'apelsin_data' => $apelsin
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$message = "Quyoshli vash zakaz: {$order->id} zavershen!";
|
||||
} else {
|
||||
abort(403, 'Мы от тебя не ждали :(');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($message)) {
|
||||
$this->sms->send($order->user->phone, $message);
|
||||
}
|
||||
|
||||
if ($request->type != 'default')
|
||||
$order->save();
|
||||
|
||||
OrdersComment::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'comment' => $request->comment,
|
||||
'order_id' => $request->order_id,
|
||||
'type' => $request->type
|
||||
]);
|
||||
|
||||
if ($order->payment_type == 'credit' && ($request->type == 'closed' || $request->type == 'completed')) {
|
||||
if ($apelsin['status']) {
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
} else {
|
||||
$this->error('Произошла ошибка в Apelsin Credit');
|
||||
}
|
||||
} else {
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$orders = Order::all();
|
||||
return Excel::download(new OrdersExport, 'reports.xlsx');
|
||||
}
|
||||
}
|
||||
109
app/Http/Controllers/Dashboard/Page/Controller.php
Executable file
109
app/Http/Controllers/Dashboard/Page/Controller.php
Executable file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Page;
|
||||
|
||||
use App\Models\Page;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Page\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Page\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Page\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Page\Update as UpdateJob;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $pages;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Brend $page
|
||||
*/
|
||||
public function __construct(Page $page)
|
||||
{
|
||||
$this->pages = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Page $page
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Page $page)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'pages');
|
||||
return view('dashboard.pages.edit', compact('page'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($page, $request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'pages');
|
||||
return view('dashboard.pages.create');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Page $page
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Page $page)
|
||||
{
|
||||
$page->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function image_upload(Request $request)
|
||||
{
|
||||
if ($request->hasFile('file')) {
|
||||
$folder = Carbon::now()->format('Y/m/d');
|
||||
$path = $request->file('file')->store("uploads/posts/{$folder}");
|
||||
|
||||
return response()->json([
|
||||
'image' => $path
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => false
|
||||
], 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Page $page
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Page $page)
|
||||
{
|
||||
$page->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
94
app/Http/Controllers/Dashboard/Partner/Controller.php
Executable file
94
app/Http/Controllers/Dashboard/Partner/Controller.php
Executable file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Partner;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Partner;
|
||||
|
||||
use App\Http\Requests\Dashboard\Partner\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Partner\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Partner\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Partner\Update as UpdateJob;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'partners');
|
||||
$partners = Partner::orderBy('position')->paginate(20);
|
||||
return view('dashboard.partners.index', compact('partners'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('create', 'partners');
|
||||
return view('dashboard.partners.create');
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/partners');
|
||||
}
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.partners.index');
|
||||
}
|
||||
|
||||
public function edit(Partner $partner)
|
||||
{
|
||||
$this->authorize('update', 'partners');
|
||||
return view('dashboard.partners.edit', compact('partner'));
|
||||
}
|
||||
|
||||
public function update(UpdateRequest $request, Partner $partner)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
// delete old image from s3
|
||||
Storage::disk('s3')->delete($partner->image);
|
||||
} else {
|
||||
// detele old image
|
||||
$imagePath = public_path($partner->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
$path = $request->file('image')->store('uploads/partners');
|
||||
} else {
|
||||
$path = $partner->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($partner, $request, $path));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.partners.index');
|
||||
}
|
||||
|
||||
public function destroy(Partner $partner)
|
||||
{
|
||||
$this->authorize('delete', 'partners');
|
||||
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
// delete old image from s3
|
||||
Storage::disk('s3')->delete($partner->image);
|
||||
} else {
|
||||
$imagePath = public_path($partner->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
$partner->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/Dashboard/PartnerRequest/Controller.php
Executable file
38
app/Http/Controllers/Dashboard/PartnerRequest/Controller.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\PartnerRequest;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\PartnerRequest;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$requests = PartnerRequest::latest('id')->paginate(20);
|
||||
return view('dashboard.partners.requests.index', compact('requests'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$partnerRequest = PartnerRequest::findOrFail($id);
|
||||
return view('dashboard.partners.requests.show', compact('partnerRequest'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// validate request
|
||||
$request->validate([
|
||||
'status' => 'required|in:approved,rejected,closed,pending'
|
||||
]);
|
||||
|
||||
$partnerRequest = PartnerRequest::findOrFail($id);
|
||||
$partnerRequest->update([
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.partner_requests.index');
|
||||
}
|
||||
}
|
||||
92
app/Http/Controllers/Dashboard/PaymentSystem/PaymentSystemController.php
Executable file
92
app/Http/Controllers/Dashboard/PaymentSystem/PaymentSystemController.php
Executable file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\PaymentSystem;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\PaymentSystemModel as PaymentSystem;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PaymentSystemController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$paymentSystems = PaymentSystem::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.payment-systems.index', compact('paymentSystems'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('dashboard.payment-systems.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string',
|
||||
'title_ru' => 'required|string',
|
||||
]);
|
||||
|
||||
// generate slug from title_uz
|
||||
$slug = Str::slug($request->slug);
|
||||
|
||||
PaymentSystem::create([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
'slug' => $slug,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.payment-systems.index');
|
||||
}
|
||||
|
||||
public function edit($systemId)
|
||||
{
|
||||
$paymentSystem = PaymentSystem::findOrFail($systemId);
|
||||
return view('dashboard.payment-systems.edit', compact('paymentSystem'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $systemId)
|
||||
{
|
||||
$paymentSystem = PaymentSystem::findOrFail($systemId);
|
||||
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string',
|
||||
'title_ru' => 'required|string',
|
||||
]);
|
||||
|
||||
// generate slug from title_uz
|
||||
$slug = Str::slug($request->slug);
|
||||
|
||||
$paymentSystem->update([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
'slug' => $slug,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.payment-systems.index');
|
||||
}
|
||||
|
||||
public function destroy($systemId)
|
||||
{
|
||||
$paymentSystem = PaymentSystem::findOrFail($systemId);
|
||||
|
||||
// delete related items and their logos
|
||||
foreach ($paymentSystem->items as $item) {
|
||||
Storage::delete($item->logo);
|
||||
$item->delete();
|
||||
}
|
||||
|
||||
$paymentSystem->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
146
app/Http/Controllers/Dashboard/PaymentSystem/PaymentSystemItemController.php
Executable file
146
app/Http/Controllers/Dashboard/PaymentSystem/PaymentSystemItemController.php
Executable file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\PaymentSystem;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\PaymentSystemItem;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PaymentSystemItemController extends ExController
|
||||
{
|
||||
public function index($paymentSystemId)
|
||||
{
|
||||
$items = PaymentSystemItem::latest('id')->where('payment_system_id', $paymentSystemId)->get();
|
||||
|
||||
return view('dashboard.payment-systems.items.index', compact('items', 'paymentSystemId'));
|
||||
}
|
||||
|
||||
public function create($paymentSystemId)
|
||||
{
|
||||
return view('dashboard.payment-systems.items.create', compact('paymentSystemId'));
|
||||
}
|
||||
|
||||
public function store(Request $request, $paymentSystemId)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string',
|
||||
'title_ru' => 'required|string',
|
||||
'description_uz' => 'nullable|string',
|
||||
'description_ru' => 'nullable|string',
|
||||
'logo' => 'required|image',
|
||||
]);
|
||||
|
||||
// store logo to storage
|
||||
$logo = $request->file('logo');
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$folder = "uploads/payment-system-items";
|
||||
$logoPath = $logo->store($folder);
|
||||
} else {
|
||||
$logoName = Str::random(20) . '.' . $logo->extension();
|
||||
$logo->storeAs('uploads/payment-system-items', $logoName);
|
||||
$logoPath = 'uploads/payment-system-items/' . $logoName;
|
||||
}
|
||||
|
||||
// generate slug from title_uz
|
||||
$slug = Str::slug($request->title_uz);
|
||||
|
||||
if ($request->has('description_uz') && $request->has('description_ru')) {
|
||||
$description = [
|
||||
'uz' => $request->description_uz,
|
||||
'ru' => $request->description_ru,
|
||||
];
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
|
||||
PaymentSystemItem::create([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
'payment_system_id' => $paymentSystemId,
|
||||
'description' => $description,
|
||||
'slug' => $slug,
|
||||
'logo' => $logoPath
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.payment-system-items.index', $paymentSystemId);
|
||||
}
|
||||
|
||||
public function edit($paymentSystemId, $systemId)
|
||||
{
|
||||
|
||||
$item = PaymentSystemItem::findOrFail($systemId);
|
||||
return view('dashboard.payment-systems.items.edit', compact('item', 'paymentSystemId'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $paymentSystemId, $systemId)
|
||||
{
|
||||
$item = PaymentSystemItem::findOrFail($systemId);
|
||||
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string',
|
||||
'title_ru' => 'required|string',
|
||||
'description_uz' => 'nullable|string',
|
||||
'description_ru' => 'nullable|string',
|
||||
'logo' => 'nullable|image',
|
||||
]);
|
||||
|
||||
// generate slug from title_uz
|
||||
$slug = Str::slug($request->title_uz);
|
||||
|
||||
if ($request->has('description_uz') && $request->has('description_ru')) {
|
||||
$description = [
|
||||
'uz' => $request->description_uz,
|
||||
'ru' => $request->description_ru,
|
||||
];
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('logo')) {
|
||||
// delete old logo
|
||||
Storage::delete($item->logo);
|
||||
|
||||
// store logo to storage
|
||||
$logo = $request->file('logo');
|
||||
// with generated name
|
||||
// generate name with 20 string
|
||||
$logoName = Str::random(20) . '.' . $logo->extension();
|
||||
$logo->storeAs('uploads/payment-system-items', $logoName);
|
||||
|
||||
$logo = 'uploads/payment-system-items/' . $logoName;
|
||||
} else {
|
||||
$logo = $item->logo;
|
||||
}
|
||||
|
||||
$item->update([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
'payment_system_id' => $paymentSystemId,
|
||||
'description' => $description,
|
||||
'slug' => $slug,
|
||||
'logo' => $logo,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.payment-system-items.index', $paymentSystemId);
|
||||
}
|
||||
|
||||
public function destroy($paymentSystemId, $systemId)
|
||||
{
|
||||
$item = PaymentSystemItem::findOrFail($systemId);
|
||||
|
||||
Storage::delete($item->logo);
|
||||
|
||||
$item->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
153
app/Http/Controllers/Dashboard/Post/Controller.php
Executable file
153
app/Http/Controllers/Dashboard/Post/Controller.php
Executable file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Post;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Post;
|
||||
|
||||
use App\Http\Requests\Dashboard\Post\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Post\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Post\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Post\Update as UpdateJob;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $posts;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->posts = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $lang
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index($lang)
|
||||
{
|
||||
$this->authorize('view', 'posts');
|
||||
$posts = $this->posts->orderBy('position')->latest('id')
|
||||
->where('language', $lang)
|
||||
->paginate(20);
|
||||
return view('dashboard.posts.index', compact('posts', 'lang'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param $lang
|
||||
* @param Post $post
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, $lang, Post $post)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'posts');
|
||||
return view('dashboard.posts.update', compact('lang', 'post'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
Storage::disk('s3')->delete($post->image);
|
||||
} else {
|
||||
if (is_file($post->image)) {
|
||||
unlink($post->image);
|
||||
}
|
||||
}
|
||||
$path = $request->file('image')->store('uploads/posts');
|
||||
} else {
|
||||
$path = $post->image;
|
||||
}
|
||||
|
||||
// if ($request->has('topped')) {
|
||||
// DB::table('posts')
|
||||
// ->where('topped', true)
|
||||
// ->where('language', $lang)
|
||||
// ->update([
|
||||
// 'topped' => false
|
||||
// ]);
|
||||
// }
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($post, $request, $path));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.posts', $lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @param $lang
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request, $lang)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'posts');
|
||||
return view('dashboard.posts.store', compact('lang'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/posts');
|
||||
}
|
||||
|
||||
if ($request->has('topped')) {
|
||||
DB::table('posts')
|
||||
->where('topped', true)
|
||||
->where('language', $lang)
|
||||
->update([
|
||||
'topped' => false
|
||||
]);
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.posts', $lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Post $post)
|
||||
{
|
||||
$this->authorize('delete', 'posts');
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
Storage::disk('s3')->delete($post->image);
|
||||
} else {
|
||||
if (is_file($post->image)) {
|
||||
unlink($post->image);
|
||||
}
|
||||
}
|
||||
|
||||
$post->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function image_upload(Request $request)
|
||||
{
|
||||
if ($request->hasFile('file')) {
|
||||
$folder = Carbon::now()->format('Y/m/d');
|
||||
$path = $request->file('file')->store("uploads/posts/{$folder}");
|
||||
|
||||
return response()->json([
|
||||
'image' => $path
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => false
|
||||
], 403);
|
||||
}
|
||||
}
|
||||
87
app/Http/Controllers/Dashboard/Power/PowerController.php
Executable file
87
app/Http/Controllers/Dashboard/Power/PowerController.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Power;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Power;
|
||||
|
||||
class PowerController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// $this->authorize('view', 'powers');
|
||||
|
||||
$powers = Power::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.powers.index', compact('powers'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
// $this->authorize('create', 'powers');
|
||||
|
||||
return view('dashboard.powers.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// $this->authorize('create', 'powers');
|
||||
|
||||
$this->validate($request, [
|
||||
'name_uz' => 'required|string|max:255',
|
||||
'name_ru' => 'required|string|max:255',
|
||||
'value' => 'required|numeric',
|
||||
]);
|
||||
|
||||
Power::create([
|
||||
'name' => [
|
||||
'uz' => $request->name_uz,
|
||||
'ru' => $request->name_ru,
|
||||
],
|
||||
'power' => $request->value,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.powers.index');
|
||||
}
|
||||
|
||||
public function edit(Power $power)
|
||||
{
|
||||
// $this->authorize('update', 'powers');
|
||||
|
||||
return view('dashboard.powers.edit', compact('power'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Power $power)
|
||||
{
|
||||
// $this->authorize('update', 'powers');
|
||||
|
||||
$this->validate($request, [
|
||||
'name_uz' => 'required|string|max:255',
|
||||
'name_ru' => 'required|string|max:255',
|
||||
'value' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$power->update([
|
||||
'name' => [
|
||||
'uz' => $request->name_uz,
|
||||
'ru' => $request->name_ru,
|
||||
],
|
||||
'power' => $request->value,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.powers.index');
|
||||
}
|
||||
|
||||
public function destroy(Power $power)
|
||||
{
|
||||
// $this->authorize('delete', 'powers');
|
||||
|
||||
$power->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
71
app/Http/Controllers/Dashboard/Problem/ProblemController.php
Executable file
71
app/Http/Controllers/Dashboard/Problem/ProblemController.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Problem;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Problem;
|
||||
|
||||
class ProblemController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$problems = Problem::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.problems.index', compact('problems'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('dashboard.problems.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string|max:255',
|
||||
'title_ru' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
Problem::create([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.problems.index');
|
||||
}
|
||||
|
||||
public function edit(Problem $problem)
|
||||
{
|
||||
return view('dashboard.problems.edit', compact('problem'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Problem $problem)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title_uz' => 'required|string|max:255',
|
||||
'title_ru' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$problem->update([
|
||||
'title' => [
|
||||
'uz' => $request->title_uz,
|
||||
'ru' => $request->title_ru,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.problems.index');
|
||||
}
|
||||
|
||||
public function destroy(Problem $problem)
|
||||
{
|
||||
$problem->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
621
app/Http/Controllers/Dashboard/Product/Controller.php
Executable file
621
app/Http/Controllers/Dashboard/Product/Controller.php
Executable file
@@ -0,0 +1,621 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Product;
|
||||
|
||||
use App\Exports\ProductsForPriceExport;
|
||||
use App\Helpers\MassAction;
|
||||
use App\Imports\MobileImport;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Color;
|
||||
use App\Models\Measurement;
|
||||
use App\Models\Preview;
|
||||
use App\Models\Screen;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use App\Queries\Category as CategoryQuery;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Product\Store as StoreRequest;
|
||||
use App\Http\Requests\Dashboard\Product\Update as UpdateRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Product\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Product\Child as ChildJob;
|
||||
use App\Jobs\Dashboard\Product\ChildUpdate as ChildUpdateJob;
|
||||
use App\Jobs\Dashboard\Product\Update as UpdateJob;
|
||||
use App\Jobs\Dashboard\Product\Deletes as DeletesJob;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $products;
|
||||
protected $categories;
|
||||
protected $brands;
|
||||
protected $colors;
|
||||
protected $categoryQuery;
|
||||
/**
|
||||
* @var MassAction
|
||||
*/
|
||||
private $massAction;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Product $product
|
||||
* @param Category $category
|
||||
* @param Brand $brand
|
||||
* @param Color $color
|
||||
*/
|
||||
public function __construct(Product $product, Category $category, Brand $brand, Color $color)
|
||||
{
|
||||
$this->products = $product;
|
||||
$this->categories = $category;
|
||||
$this->brands = $brand;
|
||||
$this->colors = $color;
|
||||
$this->categoryQuery = new CategoryQuery();
|
||||
$this->massAction = new MassAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', 'products');
|
||||
$products = $this->products->latest('id')->whereNull('child_id')->paginate($request->paginate ?? 15);
|
||||
$categories = Category::whereNull('parent_id')->get();
|
||||
|
||||
return view('dashboard.products.index', compact('products', 'categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'products');
|
||||
$categories = $this->categories->select('id', 'name->ru as category')
|
||||
->where('parent_id', null)
|
||||
->with(['parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id')->with(['parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id');
|
||||
}]);
|
||||
}])->get();
|
||||
$brands = $this->brands->get();
|
||||
$colors = $this->colors->get();
|
||||
$measurement = Measurement::query()->get();
|
||||
|
||||
return view('dashboard.products.store', compact('categories', 'brands', 'colors', 'measurement'));
|
||||
}
|
||||
|
||||
$product = $this->dispatchSync(StoreJob::fromRequest($request));
|
||||
|
||||
$product->categories()->attach([$request->getCategoryID()]);
|
||||
|
||||
$this->charSync($product, $request->characteristics);
|
||||
$this->dispatchSync(new ChildJob($request, $product));
|
||||
|
||||
$this->success(trans('admin.messages.created'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $product
|
||||
* @param $char
|
||||
*/
|
||||
private function charSync($product, $char)
|
||||
{
|
||||
$sync_data = [];
|
||||
|
||||
if (!empty($char)) {
|
||||
$ids = collect($char)->map(function ($char) {
|
||||
return (int) $char['id'];
|
||||
});
|
||||
|
||||
$product->characteristics()->detach($ids);
|
||||
|
||||
for ($i = 0; $i < count($char); $i++) {
|
||||
if ($char[$i]['value']) {
|
||||
$sync_data[$char[$i]['id']] = ['value' => $char[$i]['value']];
|
||||
}
|
||||
}
|
||||
|
||||
$product->characteristics()->attach($sync_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function characteristics($id)
|
||||
{
|
||||
$category = Category::find($id);
|
||||
|
||||
|
||||
if (!empty($category->characteristics) && count($category->characteristics) > 0) {
|
||||
$characteristics = $category->characteristics;
|
||||
} else {
|
||||
if (!empty($category->parent)) {
|
||||
$characteristics = $category->parent->characteristics;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($characteristics)) {
|
||||
$characteristics = $category->characteristics;
|
||||
}
|
||||
|
||||
$characteristics->map(function ($characteristic) {
|
||||
if ($characteristic->type == 'checkbox') {
|
||||
$characteristic->value = false;
|
||||
} else {
|
||||
$characteristic->value = null;
|
||||
}
|
||||
});
|
||||
|
||||
return [
|
||||
'status' => true,
|
||||
'characteristics' => $characteristics
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $categories
|
||||
* @return array
|
||||
*/
|
||||
private function category($categories): array
|
||||
{
|
||||
return array_map(function ($cat) {
|
||||
$arr = [];
|
||||
|
||||
if (count($cat['parents']) > 0) {
|
||||
$arr[] = [
|
||||
'id' => $cat['id'],
|
||||
'category' => $cat['name']['ru'],
|
||||
'$isDisabled' => true
|
||||
];
|
||||
|
||||
foreach ($cat['parents'] as $parent) {
|
||||
if (count($parent['parents']) > 0) {
|
||||
if (count($parent['parents']) > 0) {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => true
|
||||
];
|
||||
|
||||
foreach ($parent['parents'] as $paren) {
|
||||
$arr[] = [
|
||||
'id' => $paren['id'],
|
||||
'category' => $paren['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$arr[] = [
|
||||
'id' => $parent['id'],
|
||||
'category' => $parent['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
} else {
|
||||
$arr = [
|
||||
'id' => $cat['id'],
|
||||
'category' => $cat['name']['ru'],
|
||||
'$isDisabled' => false
|
||||
];
|
||||
return $arr;
|
||||
}
|
||||
}, $categories);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @param UpdateRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(Product $product, UpdateRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'products');
|
||||
|
||||
$product->loadMissing([
|
||||
'childrens' => function ($child) {
|
||||
return $child->select('id', 'sizes', 'color_id', 'child_id')->with([
|
||||
'color' => function ($color) {
|
||||
return $color->select('id', 'name', 'color');
|
||||
},
|
||||
'screens' => function ($screen) {
|
||||
return $screen->select('id', 'name', 'size', 'path', 'product_id', 'type');
|
||||
}
|
||||
]);
|
||||
},
|
||||
'categories' => function ($categories) {
|
||||
return $categories->select('id', 'name->ru as category', 'parent_id')->with(['parent' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id')->with(['parents', 'parent' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id')->with(['parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id');
|
||||
}]);
|
||||
}, 'parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id');
|
||||
}]);
|
||||
}]);
|
||||
},
|
||||
|
||||
'characteristics'
|
||||
]);
|
||||
|
||||
foreach ($product->childrens as $children) {
|
||||
foreach ($children->screens as $screen) {
|
||||
$screen->sizeText = $screen->size / 1024 . 'Kb';
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$screen->url = Storage::temporaryUrl(
|
||||
$screen->path,
|
||||
Date::now()->addMinutes(5)
|
||||
);
|
||||
} else {
|
||||
$screen->url = '/' . $screen->path;
|
||||
}
|
||||
$screen->type = "image/jpeg";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$categories = $this->categories->select('id', 'name->ru as category')
|
||||
->where('parent_id', null)
|
||||
->with(['parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id')->with(['parents' => function ($parent) {
|
||||
return $parent->select('id', 'name->ru as category', 'parent_id');
|
||||
}]);
|
||||
}])->get();
|
||||
|
||||
$brands = $this->brands->get();
|
||||
$measurement = Measurement::query()->get();
|
||||
$colors = $this->colors->get();
|
||||
$product->poster = $product->getPoster();
|
||||
$product->poster_thumb = $product->getPosterThumb();
|
||||
$product->data_sheet = $product->getDataSheet();
|
||||
|
||||
return view('dashboard.products.update', compact('categories', 'brands', 'colors', 'product', 'measurement'));
|
||||
}
|
||||
|
||||
try{
|
||||
$this->dispatchSync(new UpdateJob($product, $request));
|
||||
$this->dispatchSync(new ChildUpdateJob($request, $product));
|
||||
}catch(Exception $e){
|
||||
return Response::json([
|
||||
"messages" => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$this->charSync($product, $request->characteristics);
|
||||
|
||||
$this->dispatchSync(new DeletesJob($request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function delete(Product $product)
|
||||
{
|
||||
$this->authorize('delete', 'products');
|
||||
// if (is_file($product->poster)) {
|
||||
// unlink($product->poster);
|
||||
// }
|
||||
//
|
||||
// if (is_file($product->poster_thumb)) {
|
||||
// unlink($product->poster_thumb);
|
||||
// }
|
||||
//
|
||||
// $screens = Screen::where('product_id', $product->id)->get();
|
||||
// foreach ($screens as $screen) {
|
||||
// if (is_file($screen->path)) {
|
||||
// unlink($screen->path);
|
||||
// }
|
||||
//
|
||||
// if (is_file($screen->path)) {
|
||||
// unlink($screen->path_thumb);
|
||||
// }
|
||||
//
|
||||
// $screen->delete();
|
||||
// }
|
||||
//
|
||||
// foreach ($product->childrens as $children) {
|
||||
// $screens = Screen::where('product_id', $children->id)->get();
|
||||
// foreach ($screens as $screen) {
|
||||
// $this->delete_screen($screen);
|
||||
// }
|
||||
// $children->delete();
|
||||
// }
|
||||
|
||||
$product->delete();
|
||||
$product->childrens()->delete();
|
||||
|
||||
$this->error(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$id = empty($request->get('id')) ? null : $request->get('id');
|
||||
$brand = empty($request->get('brand')) ? null : $request->get('brand');
|
||||
$name = empty($request->get('name')) ? null : $request->get('name');
|
||||
$category = empty($request->get('category')) ? null : $request->get('category');
|
||||
$in_stock = empty($request->get('in_stock')) && $request->get('in_stock') == 0 ? null : $request->get('in_stock');
|
||||
$published = $request->get('published'); // ? null : $request->get('published');
|
||||
$article_number = empty($request->get('article_number')) ? null : $request->get('article_number');
|
||||
|
||||
if ($category) {
|
||||
$categoryFind = Category::find($category);
|
||||
list($categoryFind, $category_id) = $this->categoryQuery->getCategoriesAndCategoryMainId($categoryFind);
|
||||
} else {
|
||||
$category_id = [];
|
||||
}
|
||||
|
||||
if ($in_stock) {
|
||||
$products = Product::latest('id')->searchFilter($id, $brand, $category, $published, $article_number, $category_id, $name);
|
||||
|
||||
if ($in_stock == 1) {
|
||||
$products = $products->where('available', 1)->where('count', '>', 0);
|
||||
}
|
||||
} else {
|
||||
$products = Product::latest('id')->searchFilter($id, $brand, $category, $published, $article_number, $category_id, $name);
|
||||
|
||||
if ($in_stock == 0) {
|
||||
$products = $products->where('available', 0)->where('count', '>', 0)
|
||||
->orWhere('available', 1)->where('count', 0)->notChilds()->searchFilter($id, $brand, $category, $published, $article_number, $category_id, $name)
|
||||
->orWhere('available', 0)->where('count', 0)->notChilds()->searchFilter($id, $brand, $category, $published, $article_number, $category_id, $name);
|
||||
}
|
||||
}
|
||||
|
||||
$products = $products->paginate(10);
|
||||
|
||||
$categories = Category::whereNull('parent_id')->get();
|
||||
|
||||
return view('dashboard.products.index', compact('products', 'categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Screen $screen
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete_screen(Screen $screen)
|
||||
{
|
||||
if (is_file($screen->path)) {
|
||||
unlink($screen->path);
|
||||
}
|
||||
|
||||
if (is_file($screen->path_thumb)) {
|
||||
unlink($screen->path_thumb);
|
||||
}
|
||||
|
||||
$screen->delete();
|
||||
|
||||
return ['status' => true];
|
||||
}
|
||||
|
||||
public function import(Request $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$categories = Category::whereNull('parent_id')->get();
|
||||
return view('dashboard.products.import', compact('categories'));
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'file' => 'required|mimes:xlsx,xls'
|
||||
]);
|
||||
|
||||
$file = $request->file('file')->store('uploads/imports');
|
||||
|
||||
$excel = Excel::toArray(new MobileImport, $file);
|
||||
|
||||
$excel = collect($excel)->flatten(1)->map(function ($product) {
|
||||
if ($product[0] != null) {
|
||||
return $product;
|
||||
}
|
||||
})->filter(function ($value) {
|
||||
return $value != null;
|
||||
})->splice(1);
|
||||
|
||||
if ($request->category_id == 0) {
|
||||
foreach ($excel as $item) {
|
||||
$product = Product::find($item[0]);
|
||||
if (!empty($product)) {
|
||||
$product->article_number = $item[1];
|
||||
$product->price = $item[3] ? $item[3] : $product->price;
|
||||
$product->price_discount = $item[4] ? $item[4] : $product->price_discount;
|
||||
// $product->price_credit = $item[8] ? $item[8] : $product->price_credit;
|
||||
$product->count = $item[9];
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->success(trans('admin.messages.created'));
|
||||
|
||||
return redirect()->route('dashboard.products');
|
||||
}
|
||||
|
||||
Preview::query()->truncate();
|
||||
|
||||
foreach ($excel as $product) {
|
||||
Preview::create([
|
||||
'name' => [
|
||||
'ru' => $product[0],
|
||||
'uz' => $product[1],
|
||||
],
|
||||
|
||||
'brand' => $product[2],
|
||||
'price' => $product[3] ? $product[3] : 0,
|
||||
'price_discount' => $product[4],
|
||||
'article_number' => $product[5],
|
||||
'leader_of_sales' => $product[6],
|
||||
'popular' => $product[7],
|
||||
'category_id' => $request->category_id,
|
||||
|
||||
'characteristics' => [
|
||||
$product[8],
|
||||
$product[9],
|
||||
$product[10],
|
||||
$product[11],
|
||||
$product[12],
|
||||
$product[13],
|
||||
$product[14],
|
||||
$product[15],
|
||||
$product[16],
|
||||
$product[17],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$products = Preview::all();
|
||||
|
||||
$characteristics = $this->characteristics($request->category_id);
|
||||
|
||||
$category_id = $request->category_id;
|
||||
|
||||
return view('dashboard.products.preview', compact('products', 'characteristics', 'category_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function previewStore(Request $request)
|
||||
{
|
||||
$char = $this->characteristics($request->category_id);
|
||||
|
||||
$char = $char['characteristics'];
|
||||
|
||||
foreach ($request->data as $row) {
|
||||
$brand = Brand::where('name->ru', $row['brand'])->first();
|
||||
|
||||
$brand_id = !empty($brand) ? $brand->id : null;
|
||||
|
||||
$product = Product::where('article_number', $row['article_number'])->first();
|
||||
|
||||
if (!empty($product)) {
|
||||
$product->name = $row['name'];
|
||||
$product->price = $row['price'];
|
||||
$product->price_discount = $row['price_discount'];
|
||||
$product->popular = $row['popular'];
|
||||
$product->currency = 'sum';
|
||||
$product->brand_id = $brand_id;
|
||||
$product->leader_of_sales = $row['leader_of_sales'];
|
||||
$product->slug = str_slug($row['name']['ru']);
|
||||
$product->save();
|
||||
} else {
|
||||
$product = new Product();
|
||||
$product->name = $row['name'];
|
||||
$product->price = $row['price'];
|
||||
$product->body = ['ru' => '', 'uz' => ''];
|
||||
$product->short_body = ['ru' => '', 'uz' => ''];
|
||||
$product->article_number = $row['article_number'];
|
||||
$product->price_discount = $row['price_discount'];
|
||||
$product->popular = $row['popular'];
|
||||
$product->currency = 'sum';
|
||||
$product->brand_id = $brand_id;
|
||||
$product->leader_of_sales = $row['leader_of_sales'];
|
||||
$product->slug = str_slug($row['name']['ru']);
|
||||
$product->published = 0;
|
||||
$product->save();
|
||||
|
||||
$product->categories()->attach([$row['category_id']]);
|
||||
|
||||
Product::create([
|
||||
'published' => 0,
|
||||
'child_id' => $product->id
|
||||
]);
|
||||
}
|
||||
|
||||
$sync_data = [];
|
||||
|
||||
if (!empty($char) && count($char) > 0) {
|
||||
$ids = $char->map(function ($char) {
|
||||
return (int) $char['id'];
|
||||
});
|
||||
|
||||
$product->characteristics()->detach($ids);
|
||||
|
||||
for ($i = 0; $i < count($row['characteristics']); $i++) {
|
||||
if ($char[$i]['type'] == 'checkbox') {
|
||||
$value = $row['characteristics'][$i] == 1 || $row['characteristics'][$i] == true ? 'true' : 'false';
|
||||
} else {
|
||||
$value = $row['characteristics'][$i];
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
$value = 'null';
|
||||
}
|
||||
|
||||
$sync_data[$char[$i]['id']] = ['value' => $value];
|
||||
}
|
||||
|
||||
$product->characteristics()->attach($sync_data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success(trans('admin.messages.created'));
|
||||
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function massAction(Request $request)
|
||||
{
|
||||
switch ($request->input('action')) {
|
||||
case "delete":
|
||||
$this->massAction->massDelete($request->prod_id);
|
||||
break;
|
||||
case "status-deactivate":
|
||||
$this->massAction->massUnpublish($request->prod_id);
|
||||
break;
|
||||
case "status-active":
|
||||
$this->massAction->massPublish($request->prod_id);
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.success'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
return Excel::download(new ProductsForPriceExport(), 'products-export.xlsx');
|
||||
}
|
||||
}
|
||||
107
app/Http/Controllers/Dashboard/Region/Controller.php
Executable file
107
app/Http/Controllers/Dashboard/Region/Controller.php
Executable file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Region;
|
||||
|
||||
use App\Models\Region;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Region\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Region\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Region\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Region\Update as UpdateJob;
|
||||
use App\Models\Power;
|
||||
use App\Services\Dashboard\Region\RegionService;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $regions;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Region $region
|
||||
*/
|
||||
public function __construct(Region $region)
|
||||
{
|
||||
$this->regions = $region;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'regions');
|
||||
$regions = $this->regions->latest('id')->paginate(20);
|
||||
return view('dashboard.regions.index', compact('regions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Region $region
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Region $region)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'regions');
|
||||
$powers = Power::all();
|
||||
$lang = app()->getLocale();
|
||||
return view('dashboard.regions.update', compact('region', 'powers', 'lang'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($region, $request));
|
||||
|
||||
// update or store delivery price
|
||||
if ($request->has('deliveryPrice')) {
|
||||
RegionService::deliveryPrice($region, $request->deliveryPrice);
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.regions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'regions');
|
||||
$powers = Power::all();
|
||||
$lang = app()->getLocale();
|
||||
return view('dashboard.regions.store', compact('powers', 'lang'));
|
||||
}
|
||||
|
||||
$region = $this->dispatchSync(StoreJob::fromRequest($request));
|
||||
|
||||
// store delivery price
|
||||
if ($request->has('deliveryPrice')) {
|
||||
RegionService::deliveryPrice($region, $request->deliveryPrice);
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.regions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Region $region
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function delete(Region $region)
|
||||
{
|
||||
$this->authorize('delete', 'regions');
|
||||
// delete delivery price
|
||||
$region->deliveryPrice()->delete();
|
||||
$region->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
92
app/Http/Controllers/Dashboard/Role/Controller.php
Executable file
92
app/Http/Controllers/Dashboard/Role/Controller.php
Executable file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Role;
|
||||
|
||||
use App\Models\Role;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Role\Request as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Role\Request as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Role\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Role\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $roles;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Role $role
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function __construct(Role $role)
|
||||
{
|
||||
$this->roles = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'roles');
|
||||
$roles = $this->roles->latest('id')
|
||||
->paginate(20);
|
||||
|
||||
return view('dashboard.roles.index', compact('roles'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Role $role
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Role $role)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'roles');
|
||||
return view('dashboard.roles.update', compact('role'));
|
||||
}
|
||||
|
||||
//return $request->all();
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($role, $request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.roles');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'roles');
|
||||
return view('dashboard.roles.store');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.roles');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Role $role
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Role $role)
|
||||
{
|
||||
$this->authorize('delete', 'roles');
|
||||
$role->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
127
app/Http/Controllers/Dashboard/Service/Controller.php
Executable file
127
app/Http/Controllers/Dashboard/Service/Controller.php
Executable file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Service;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\Service;
|
||||
use App\Http\Requests\Dashboard\Service\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Service\Store as StoreRequest;
|
||||
use App\Jobs\Dashboard\Service\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Service\Update as UpdateJob;
|
||||
use App\Models\Problem;
|
||||
use App\Models\ServiceProblem;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'services');
|
||||
|
||||
$services = Service::latest('id')->paginate(20);
|
||||
return view('dashboard.services.index', compact('services'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('create', 'services');
|
||||
|
||||
$problems = Problem::all();
|
||||
return view('dashboard.services.create', compact('problems'));
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/services');
|
||||
}
|
||||
|
||||
$service = $this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
|
||||
if ($request->with_problem != null) {
|
||||
foreach ($request->problems as $problem) {
|
||||
ServiceProblem::create([
|
||||
'service_id' => $service->id,
|
||||
'problem_id' => $problem
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.services.index');
|
||||
}
|
||||
|
||||
public function edit(Service $service)
|
||||
{
|
||||
$this->authorize('update', 'services');
|
||||
$problems = Problem::all();
|
||||
return view('dashboard.services.edit', compact('service', 'problems'));
|
||||
}
|
||||
|
||||
public function update(UpdateRequest $request, Service $service)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$imagePath = $service->image;
|
||||
Storage::disk('s3')->delete($imagePath);
|
||||
} else {
|
||||
$imagePath = public_path($service->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
$path = $request->file('image')->store('uploads/services');
|
||||
} else {
|
||||
$path = $service->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($service, $request, $path));
|
||||
|
||||
$existingProblemIds = $service->problems->pluck('id')->toArray();
|
||||
$newProblemIds = $request->problems ?? [];
|
||||
|
||||
$toDelete = array_diff($existingProblemIds, $newProblemIds);
|
||||
$toAdd = array_diff($newProblemIds, $existingProblemIds);
|
||||
|
||||
if ($request->with_problem != null) {
|
||||
foreach ($toAdd as $problem) {
|
||||
ServiceProblem::create([
|
||||
'service_id' => $service->id,
|
||||
'problem_id' => $problem
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
ServiceProblem::where('service_id', $service->id)->delete();
|
||||
}
|
||||
ServiceProblem::whereIn('problem_id', $toDelete)->delete();
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.services.index');
|
||||
}
|
||||
|
||||
public function destroy(Service $service)
|
||||
{
|
||||
$this->authorize('delete', 'services');
|
||||
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$imagePath = $service->image;
|
||||
Storage::disk('s3')->delete($imagePath);
|
||||
} else {
|
||||
$imagePath = public_path($service->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
ServiceProblem::where('service_id', $service->id)->delete();
|
||||
|
||||
$service->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/Dashboard/ServiceRequest/Controller.php
Executable file
38
app/Http/Controllers/Dashboard/ServiceRequest/Controller.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\ServiceRequest;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\ServiceRequest;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$requests = ServiceRequest::latest('id')->paginate(20);
|
||||
return view('dashboard.services.requests.index', compact('requests'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$serviceRequest = ServiceRequest::findOrFail($id);
|
||||
return view('dashboard.services.requests.show', compact('serviceRequest'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// validate request
|
||||
$request->validate([
|
||||
'status' => 'required|in:approved,rejected,closed,pending'
|
||||
]);
|
||||
|
||||
$serviceRequest = ServiceRequest::findOrFail($id);
|
||||
$serviceRequest->update([
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.service_requests.index');
|
||||
}
|
||||
}
|
||||
75
app/Http/Controllers/Dashboard/Setting/Controller.php
Executable file
75
app/Http/Controllers/Dashboard/Setting/Controller.php
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Setting;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Setting\Update as UpdateRequest;
|
||||
use App\Jobs\Dashboard\Setting\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $setting;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Setting $setting
|
||||
*/
|
||||
public function __construct(Setting $setting)
|
||||
{
|
||||
$this->setting = $setting->find(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('update', 'settings');
|
||||
$setting = $this->setting;
|
||||
return view('dashboard.settings.index', compact('setting'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Setting $setting
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateRequest $request, Setting $setting)
|
||||
{
|
||||
$this->dispatchSync(UpdateJob::fromRequest($setting, $request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function delivery(Request $request)
|
||||
{
|
||||
// $this->authorize('delivery', 'settings');
|
||||
Gate::check('update', 'settings');
|
||||
$setting = $this->setting;
|
||||
|
||||
if ($request->isMethod('get')) {
|
||||
return view('dashboard.settings.delivery', compact('setting'));
|
||||
}
|
||||
|
||||
$pickup = $request->pickup == 1 ? true : false;
|
||||
$delivery = $request->delivery == 1 ? true : false;
|
||||
|
||||
$setting->update([
|
||||
'price_delivery' => $request->price_delivery,
|
||||
'pickup' => $pickup,
|
||||
'delivery' => $delivery,
|
||||
'day_delivery' => $request->day_delivery,
|
||||
'pickup_text' => '',
|
||||
'other' => ''
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
110
app/Http/Controllers/Dashboard/Slider/Controller.php
Executable file
110
app/Http/Controllers/Dashboard/Slider/Controller.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Slider;
|
||||
|
||||
use App\Models\Slider;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\Slider\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\Slider\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\Slider\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Slider\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $sliders;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param Slider $slider
|
||||
*/
|
||||
public function __construct(Slider $slider)
|
||||
{
|
||||
$this->sliders = $slider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'sliders');
|
||||
$sliders = $this->sliders->orderBy('position', 'asc')->get();
|
||||
|
||||
return view('dashboard.sliders.index', compact('sliders'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Slider $slider
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Slider $slider)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'sliders');
|
||||
return view('dashboard.sliders.update', compact('slider'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/sliders');
|
||||
} else {
|
||||
$path = $slider->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($slider, $request, $path));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.sliders');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'sliders');
|
||||
return view('dashboard.sliders.store');
|
||||
}
|
||||
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/sliders');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.sliders');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Slider $slider
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(Slider $slider)
|
||||
{
|
||||
$this->authorize('delete', 'sliders');
|
||||
if (is_file($slider->image)) {
|
||||
unlink($slider->image);
|
||||
}
|
||||
|
||||
$slider->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function position(Request $req)
|
||||
{
|
||||
foreach ($req->input('sliders') as $slider) {
|
||||
Slider::find($slider['id'])->update(['position' => $slider['position']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
98
app/Http/Controllers/Dashboard/SpecialOffer/Controller.php
Executable file
98
app/Http/Controllers/Dashboard/SpecialOffer/Controller.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\SpecialOffer;
|
||||
|
||||
use App\Models\SpecialOffer;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\SpecialOffer\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\SpecialOffer\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\SpecialOffer\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\SpecialOffer\Update as UpdateJob;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
|
||||
protected $specialOffers;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param SpecialOffer $specialOffer
|
||||
*/
|
||||
public function __construct(SpecialOffer $specialOffer)
|
||||
{
|
||||
$this->specialOffers = $specialOffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'special-offers');
|
||||
$specialOffers = $this->specialOffers->latest('id')->paginate(20);
|
||||
return view('dashboard.specialOffers.index', compact('specialOffers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param SpecialOffer $specialOffer
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function update(UpdateRequest $request, SpecialOffer $specialOffer)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('update', 'special-offers');
|
||||
return view('dashboard.specialOffers.update', compact('specialOffer'));
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/specialOffers');
|
||||
} else {
|
||||
$path = $specialOffer->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($specialOffer, $request, $path));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.specialOffers');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'special-offers');
|
||||
return view('dashboard.specialOffers.store');
|
||||
}
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/specialOffers');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.specialOffers');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SpecialOffer $specialOffer
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(SpecialOffer $specialOffer)
|
||||
{
|
||||
$this->authorize('delete', 'special-offers');
|
||||
|
||||
if (is_file($specialOffer->image)) {
|
||||
unlink($specialOffer->image);
|
||||
}
|
||||
|
||||
$specialOffer->delete();
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
78
app/Http/Controllers/Dashboard/Status/StatusController.php
Executable file
78
app/Http/Controllers/Dashboard/Status/StatusController.php
Executable file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\Status;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Status;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StatusController extends ExController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$statuses = Status::latest('id')->paginate(30);
|
||||
|
||||
return view('dashboard.statuses.index', compact('statuses'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('dashboard.statuses.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'slug' => 'required|string|unique:statuses',
|
||||
'font_color' => 'required|string',
|
||||
'bg_color' => 'required|string',
|
||||
]);
|
||||
|
||||
Status::create([
|
||||
'slug' => $request->slug,
|
||||
'font_color' => $request->font_color,
|
||||
'bg_color' => $request->bg_color,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.statuses.index');
|
||||
}
|
||||
|
||||
public function edit($statusId)
|
||||
{
|
||||
$status = Status::findOrFail($statusId);
|
||||
return view('dashboard.statuses.edit', compact('status'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $statusId)
|
||||
{
|
||||
$status = Status::findOrFail($statusId);
|
||||
|
||||
$this->validate($request, [
|
||||
'slug' => 'required|string|unique:statuses,slug,' . $status->id,
|
||||
'font_color' => 'required|string',
|
||||
'bg_color' => 'required|string',
|
||||
]);
|
||||
|
||||
$status->update([
|
||||
'slug' => $request->slug,
|
||||
'font_color' => $request->font_color,
|
||||
'bg_color' => $request->bg_color,
|
||||
]);
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.statuses.index');
|
||||
}
|
||||
|
||||
public function destroy($statusId)
|
||||
{
|
||||
$status = Status::findOrFail($statusId);
|
||||
|
||||
$status->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
106
app/Http/Controllers/Dashboard/UsefulInfoController/Controller.php
Executable file
106
app/Http/Controllers/Dashboard/UsefulInfoController/Controller.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\UsefulInfoController;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
use App\Models\UsefulInfo;
|
||||
|
||||
use App\Http\Requests\Dashboard\UsefulInfoRequest\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\UsefulInfoRequest\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\UsefulInfoJob\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\UsefulInfoJob\Update as UpdateJob;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view', 'usefulinfos');
|
||||
|
||||
$usefulinfos = UsefulInfo::orderBy('position')->latest('id')->paginate(20);
|
||||
return view('dashboard.usefulinfos.index', compact('usefulinfos'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('create', 'usefulinfos');
|
||||
return view('dashboard.usefulinfos.create');
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('uploads/usefulinfos');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $path));
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.usefulinfos.index');
|
||||
}
|
||||
|
||||
public function edit(UsefulInfo $usefulinfo)
|
||||
{
|
||||
$this->authorize('update', 'usefulinfos');
|
||||
return view('dashboard.usefulinfos.edit', compact('usefulinfo'));
|
||||
}
|
||||
|
||||
public function update(UpdateRequest $request, UsefulInfo $usefulinfo)
|
||||
{
|
||||
if ($request->hasFile('image')) {
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$imagePath = $usefulinfo->image;
|
||||
Storage::disk('s3')->delete($imagePath);
|
||||
} else {
|
||||
$imagePath = public_path($usefulinfo->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
$path = $request->file('image')->store('uploads/usefulinfos');
|
||||
} else {
|
||||
$path = $usefulinfo->image;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($usefulinfo, $request, $path));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.usefulinfos.index');
|
||||
}
|
||||
|
||||
public function destroy(UsefulInfo $usefulinfo)
|
||||
{
|
||||
$this->authorize('delete', 'usefulinfos');
|
||||
|
||||
// delete items files
|
||||
foreach ($usefulinfo->items as $item) {
|
||||
$filePath = public_path($item->file_url);
|
||||
|
||||
if (File::exists($filePath)) {
|
||||
File::delete($filePath);
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
}
|
||||
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$imagePath = $usefulinfo->image;
|
||||
Storage::disk('s3')->delete($imagePath);
|
||||
} else {
|
||||
$imagePath = public_path($usefulinfo->image);
|
||||
|
||||
if (File::exists($imagePath)) {
|
||||
File::delete($imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
$usefulinfo->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
89
app/Http/Controllers/Dashboard/UsefulInfoItemController/Controller.php
Executable file
89
app/Http/Controllers/Dashboard/UsefulInfoItemController/Controller.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\UsefulInfoItemController;
|
||||
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\UsefulInfoItemRequest\Update as UpdateRequest;
|
||||
use App\Http\Requests\Dashboard\UsefulInfoItemRequest\Store as StoreRequest;
|
||||
|
||||
use App\Jobs\Dashboard\UsefulInfoItemJob\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\UsefulInfoItemJob\Update as UpdateJob;
|
||||
use App\Models\UsefulInfo;
|
||||
use App\Models\UsefulInfoItem;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
public function index($usefulinfo_id)
|
||||
{
|
||||
$this->authorize('view', 'usefulinfoitems');
|
||||
|
||||
$items = UsefulInfoItem::where('useful_info_id', $usefulinfo_id)
|
||||
->latest('id')->paginate(20);
|
||||
|
||||
return view('dashboard.usefulinfos.usefulinfos_item.index', compact('items', 'usefulinfo_id'));
|
||||
}
|
||||
|
||||
public function create($usefulinfo_id)
|
||||
{
|
||||
$this->authorize('create', 'usefulinfoitem');
|
||||
return view('dashboard.usefulinfos.usefulinfos_item.create', compact('usefulinfo_id'));
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request, $usefulinfo_id)
|
||||
{
|
||||
$file_path = null;
|
||||
if ($request->hasFile('file')) {
|
||||
$file_path = $request->file('file')->store('uploads/usefulinfoitems');
|
||||
}
|
||||
|
||||
$this->dispatchSync(StoreJob::fromRequest($request, $file_path, $usefulinfo_id));
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.usefulinfoitems.index', $usefulinfo_id);
|
||||
}
|
||||
|
||||
public function edit($usefulinfo_id, UsefulInfoItem $usefulinfoitem)
|
||||
{
|
||||
$this->authorize('update', 'usefulinfoitems');
|
||||
return view('dashboard.usefulinfos.usefulinfos_item.edit', compact('usefulinfoitem', 'usefulinfo_id'));
|
||||
}
|
||||
|
||||
public function update(UpdateRequest $request, $usefulinfo_id, UsefulInfoItem $usefulinfoitem)
|
||||
{
|
||||
$file_path = null;
|
||||
if ($request->hasFile('file')) {
|
||||
$filePath = public_path($usefulinfoitem->file_url);
|
||||
|
||||
if (File::exists($filePath)) {
|
||||
File::delete($filePath);
|
||||
}
|
||||
|
||||
$file_path = $request->file('file')->store('uploads/usefulinfoitems');
|
||||
} else {
|
||||
$file_path = $usefulinfoitem->file_url;
|
||||
}
|
||||
|
||||
$this->dispatchSync(UpdateJob::fromRequest($usefulinfoitem, $request, $file_path));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.usefulinfoitems.index', $usefulinfo_id);
|
||||
}
|
||||
|
||||
public function destroy($usefulinfo_id, UsefulInfoItem $usefulinfoitem)
|
||||
{
|
||||
$this->authorize('delete', 'usefulinfoitems');
|
||||
|
||||
$filePath = public_path($usefulinfoitem->file_url);
|
||||
|
||||
if (File::exists($filePath)) {
|
||||
File::delete($filePath);
|
||||
}
|
||||
|
||||
$usefulinfoitem->delete();
|
||||
|
||||
$this->info(trans('admin.messages.deleted'));
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
164
app/Http/Controllers/Dashboard/User/Controller.php
Executable file
164
app/Http/Controllers/Dashboard/User/Controller.php
Executable file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard\User;
|
||||
|
||||
use App\Exports\UsersExport;
|
||||
use App\Http\Requests\Dashboard\User\Create as CreateRequest;
|
||||
use App\Imports\UsersImport;
|
||||
use App\Jobs\Dashboard\User\Create;
|
||||
use App\Models\Role;
|
||||
use App\Models\Staff;
|
||||
use App\Models\User;
|
||||
use App\Http\Controllers\Controller as ExController;
|
||||
|
||||
use App\Http\Requests\Dashboard\User\Update as UpdateRequest;
|
||||
|
||||
use App\Jobs\Dashboard\User\Update as UpdateJob;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class Controller extends ExController
|
||||
{
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->users = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', 'users');
|
||||
$users = $this->users->latest('id');
|
||||
|
||||
if (!is_null($request->date_from)) {
|
||||
$users = $users->filterByDate($request->date_from, $request->date_to, $request->sort_type);
|
||||
}
|
||||
|
||||
$users = $users->search($request->search_id, $request->search_phone, $request->search_ip)->paginate(30);
|
||||
|
||||
return view('dashboard.users.index', compact('users'));
|
||||
}
|
||||
|
||||
public function getStaffs()
|
||||
{
|
||||
$this->authorize('view', 'staffs');
|
||||
|
||||
$staffs = Staff::with('role')
|
||||
->oldest('id')
|
||||
->where('role_id', '!=', 2)
|
||||
->paginate(30);
|
||||
|
||||
return view('dashboard.users.staffs', compact('staffs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Staff $staff
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function block(Staff $staff)
|
||||
{
|
||||
$this->authorize('update', 'staffs');
|
||||
|
||||
if ($staff->block === true) {
|
||||
$staff->block = false;
|
||||
} else {
|
||||
$staff->block = true;
|
||||
}
|
||||
|
||||
$staff->save();
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function store(CreateRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'staffs');
|
||||
$roles = Role::whereNotIn('id', [2])->get();
|
||||
return view('dashboard.users.create', compact('roles'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(new Create($request));
|
||||
|
||||
$this->info(trans('admin.messages.created'));
|
||||
return redirect()->route('dashboard.staffs');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdateRequest $request
|
||||
* @param Staff $staff
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, Staff $staff)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
|
||||
$this->authorize('update', 'staffs');
|
||||
|
||||
$roles = Role::whereNotIn('id', [2])->get();
|
||||
return view('dashboard.users.update', compact('staff', 'roles'));
|
||||
}
|
||||
$this->dispatchSync(new UpdateJob($staff, $request));
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
return redirect()->route('dashboard.staffs');
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$file = '/customers.csv';
|
||||
|
||||
$excel = Excel::toArray(new UsersImport, $file);
|
||||
|
||||
$users = collect($excel)->flatten(1);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$phone = str_replace(['+', '(', ')', ' ', '-'], '', $user[8]);
|
||||
$user = User::where('phone', $phone)->first();
|
||||
if (empty($user)) {
|
||||
if (!empty($user[8])) {
|
||||
User::create([
|
||||
'first_name' => !empty($user[4]) ? $user[4] : null,
|
||||
'last_name' => !empty($user[5]) ? $user[5] : null,
|
||||
'phone' => str_replace(['+', '(', ')', ' ', '-'], '', $user[8]),
|
||||
'email' => !empty($user[7]) ? $user[7] : null,
|
||||
'ip' => !empty($user[17]) ? $user[17] : null,
|
||||
'role_id' => 2,
|
||||
'step' => 3
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
return (new UsersExport($request->date_from, $request->date_to, $request->search_id, $request->search_phone, $request->search_ip, $request->sort_type))
|
||||
->download("users_" . now()->toDateString() . ".xlsx");
|
||||
}
|
||||
|
||||
public static function addHours()
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->update([
|
||||
'created_at' => $user->created_at->addHours(5)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user