2023-08-14 22:33:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-02-20 23:33:49 +01:00
|
|
|
use Illuminate\Http\Request;
|
2024-02-15 22:00:03 +01:00
|
|
|
use App\Services\UpdateService;
|
2024-02-20 23:33:49 +01:00
|
|
|
use App\Repositories\LocationRepository;
|
2024-09-29 23:55:55 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-08-14 22:33:53 +02:00
|
|
|
|
|
|
|
class LocationController extends Controller
|
|
|
|
{
|
2024-02-15 22:00:03 +01:00
|
|
|
protected $update;
|
2023-08-25 00:27:14 +02:00
|
|
|
|
2024-02-20 23:33:49 +01:00
|
|
|
public function __construct(
|
|
|
|
UpdateService $updateService,
|
|
|
|
LocationRepository $locationRepository
|
|
|
|
) {
|
|
|
|
$this->update = $updateService;
|
|
|
|
$this->location = $locationRepository;
|
2024-02-12 21:51:28 +01:00
|
|
|
}
|
|
|
|
|
2024-09-29 23:55:55 +02:00
|
|
|
//actions
|
2024-02-15 22:00:03 +01:00
|
|
|
public function updateLocations()
|
2024-02-12 21:51:28 +01:00
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
//role check
|
|
|
|
$member = Auth::user();
|
|
|
|
if ($member->role == 0) {
|
|
|
|
$result = $this->update->data();
|
|
|
|
return back()->with(
|
|
|
|
'message',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors('message', 'Nah, you don\'t have permission to do this');
|
|
|
|
}
|
2024-02-18 02:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function compileLocations()
|
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
//role check
|
|
|
|
$member = Auth::user();
|
|
|
|
if ($member->role == 0) {
|
|
|
|
$result = $this->update->list();
|
|
|
|
return back()->with(
|
|
|
|
'message',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors('message', 'Nah, you don\'t have permission to do this');
|
|
|
|
}
|
2023-08-25 00:27:14 +02:00
|
|
|
}
|
2024-02-20 23:33:49 +01:00
|
|
|
|
|
|
|
public function editLocation(Request $request)
|
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
$token = csrf_token();
|
|
|
|
//role check
|
|
|
|
$member = Auth::user();
|
|
|
|
if ($member->role == 0 || $member->role == 1) {
|
|
|
|
$response = $this->location->editLocation($request);
|
|
|
|
if ($response['status']) {
|
|
|
|
return back()->with('message', $response['message']);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors('message', $response['message']);
|
|
|
|
}
|
2024-02-20 23:33:49 +01:00
|
|
|
} else {
|
2024-09-29 23:55:55 +02:00
|
|
|
return back()->withErrors('message', 'Nah, you don\'t have permission to do this');
|
2024-02-20 23:33:49 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-14 22:33:53 +02:00
|
|
|
}
|