Skip to content

Commit 15ef0eb

Browse files
committed
fix: custom services
1 parent 5760c4b commit 15ef0eb

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

app/Http/Controllers/Backend/Service/CustomServiceController.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace App\Http\Controllers\Backend\Service;
44

5+
use App\DTOs\CustomService\CustomServiceDto;
56
use App\Enums\PageName;
6-
use Illuminate\Http\Request;
7-
use App\Models\CustomService;
87
use App\Http\Controllers\Controller;
9-
use App\DTOs\CustomService\CustomServiceDto;
10-
use App\Interfaces\Services\BaseServiceInterface;
11-
use App\Services\CustomService\CustomServiceService;
128
use App\Http\Requests\CustomService\CustomServiceRequest;
9+
use App\Models\CustomService;
10+
use App\Services\CustomService\CustomServiceService;
1311

1412
class CustomServiceController extends Controller
1513
{
@@ -43,8 +41,8 @@ public function store(CustomServiceRequest $request)
4341
$service->saveImage($request->file('image'));
4442
return redirect(route('custom-service.index'), 201)->with([
4543
'alert-type' => 'success',
46-
'message' => 'Custom Service Created!'
47-
]);
44+
'message' => 'Custom Service Created!',
45+
]);
4846
}
4947

5048
/**
@@ -60,8 +58,8 @@ public function show(string $id)
6058
*/
6159
public function edit(CustomService $customService)
6260
{
63-
$service = $customService;
64-
$pageNames = ['homepage', 'account'];
61+
$service = $customService;
62+
$pageNames = [ 'homepage', 'account' ];
6563
return view('backend.service.custom.edit', compact('service', 'pageNames'));
6664
}
6765

@@ -77,20 +75,22 @@ public function update(CustomServiceRequest $request, CustomService $customServi
7775
$service = $this->service->update(CustomServiceDto::transformRequest($request), $customService);
7876
return redirect(route('custom-service.index'))->with([
7977
'alert-type' => 'success',
80-
'message' => 'Custom Service Updated'
81-
]);
78+
'message' => 'Custom Service Updated',
79+
]);
8280
}
8381

8482
/**
8583
* Remove the specified resource from storage.
8684
*/
8785
public function destroy(CustomService $customService)
8886
{
89-
$customService->deleteImage($customService->image->path);
87+
if ($customService->image) {
88+
$customService->deleteImage($customService->image->path);
89+
}
9090
$this->service->delete($customService);
9191
return redirect(route('custom-service.index'))->with([
9292
'alert-type' => 'success',
93-
'message' => 'Custom Service Deleted!'
94-
]);
93+
'message' => 'Custom Service Deleted!',
94+
]);
9595
}
9696
}

app/Http/Requests/CustomService/CustomServiceRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function rules(): array
2121
'title'=>['required','string','max:255'],
2222
'description'=> ['required', 'string'],
2323
'link'=> ['required', 'starts_with:https://,http://'],
24-
'image'=> ['image', 'max:5124']
24+
'image'=> ['required','image', 'max:5124']
2525
];
2626
}
2727
}

resources/views/backend/service/custom/index.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class="badge bg-soft-success text-success font-13 text-capitalize">{{ $service->page_name }}</span>
2828
</td>
2929
<td>
30-
<img width="150" height="150" style="object-fit: cover;" src="{{ $service->image->url }}"
30+
<img width="150" height="150" style="object-fit: cover;" src="{{ $service->image?->url }}"
3131
alt="{{ str($service->title)->slug }}">
3232
</td>
3333
<td>

resources/views/components/section/custom-service.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="d-flex flex-column align-items-center border rounded shadow-sm p-2 h-100">
77
<a href="{{ $sub->link }}">
88
<img loading="lazy" style="width:clamp(80px, 120px, 150px);aspect-ratio:1/1;"
9-
class="rounded rounded-circle mb-3" src="{{ $sub->image->url }}" alt="">
9+
class="rounded rounded-circle mb-3" src="{{ $sub->image?->url }}" alt="">
1010
</a>
1111
<a class="text-dark text-capitalize" href="{{ $sub->link }}">
1212
<h6>{{ $sub->title }}</h6>

0 commit comments

Comments
 (0)