в карточку редактирования и создания новостей добавил проверку на города
This commit is contained in:
parent
f2caef5185
commit
fb85879ab6
@ -21,7 +21,6 @@ public function index()
|
||||
{
|
||||
$posts = Post::orderBy('id', 'desc');
|
||||
if (!auth()->user()->isAdmin() && auth()->user()->isCityManager()) {
|
||||
|
||||
}
|
||||
$posts = $posts->get();
|
||||
return view('admin::posts.index', [
|
||||
@ -54,7 +53,8 @@ public function store(Request $request)
|
||||
if ($request->has('cities')) {
|
||||
$availableCities = GetAvailableCities()->pluck('id')->toArray();
|
||||
foreach ($request->cities as $cityId) {
|
||||
if (!in_array($cityId, $availableCities)) {
|
||||
$city = City::find($cityId);
|
||||
if (auth()->user()->cannot('manage', $city)) {
|
||||
return back();
|
||||
}
|
||||
}
|
||||
@ -105,6 +105,18 @@ public function update(Request $request, Post $post)
|
||||
$reuqest['image'] = $post->image;
|
||||
}
|
||||
|
||||
if ($request->has('cities')) {
|
||||
$availableCities = GetAvailableCities()->pluck('id')->toArray();
|
||||
foreach ($request->cities as $cityId) {
|
||||
$city = City::find($cityId);
|
||||
if (auth()->user()->cannot('manage', $city)) {
|
||||
return back();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return back();
|
||||
}
|
||||
|
||||
$post = $post->update(
|
||||
$request->only(['name', 'short_text', 'text', 'category', 'image', 'post-trixFields'])
|
||||
);
|
||||
|
||||
@ -21,7 +21,7 @@ public function before(User $user, string $ability): bool|null
|
||||
/**
|
||||
* Determine whether the user can CRUD content (posts, agents, documents)
|
||||
*/
|
||||
public function manageContent(User $user, City $city): bool
|
||||
public function manage(User $user, City $city): bool
|
||||
{
|
||||
if (!$cityManagersOfUser = CityManager::where('user_id', $user->id)->get()) {
|
||||
return false;
|
||||
|
||||
@ -27,9 +27,10 @@ class="modal-dialog modal-dialog-scrollable modal-lg modal-fullscreen-lg-down"
|
||||
<div class="mb-2 p-2 border rounded">
|
||||
@if($availableCities = GetAvailableCities())
|
||||
<div>
|
||||
@php($citiesOfPostIds = ($post->id) ? $post->cities()->pluck('city_id')->toArray() : [])
|
||||
@foreach($availableCities as $key=>$city)
|
||||
<div class="form-check form-check-inline">
|
||||
<input name="cities[{{ $key }}]" class="form-check-input" type="checkbox" value="{{ $city->id }}" id="city_{{ $city->id }}">
|
||||
<input @checked(in_array($city->id, $citiesOfPostIds)) name="cities[{{ $key }}]" class="form-check-input" type="checkbox" value="{{ $city->id }}" id="city_{{ $city->id }}">
|
||||
<label class="form-check-label" for="city_{{ $city->id }}">
|
||||
{{ $city->name }}
|
||||
</label>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user