fix: 🐛 use static_page_id directly instead of type
This commit is contained in:
parent
10fa9c0b43
commit
79d2f53786
3 changed files with 17 additions and 10 deletions
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\NewsBreedings\StoreNewsBreedingRequest;
|
||||
use App\Http\Requests\Bo\NewsBreedings\UpdateNewsBreedingRequest;
|
||||
use App\Models\NewsBreeding;
|
||||
use App\Models\StaticPage;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
|
@ -77,7 +80,11 @@ class NewsBreedingController extends Controller
|
|||
*/
|
||||
public function create(NewsBreeding $newsBreeding): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.news_breedings.create', ['newsBreedingModel' => $newsBreeding]);
|
||||
$breedingPages = StaticPage::query()
|
||||
->whereIn('type', Arr::pluck(StaticPageType::getBreedingPages(), 'value'))
|
||||
->get();
|
||||
|
||||
return view('bo.pages.news_breedings.create', ['newsBreedingModel' => $newsBreeding, 'breedingPages' => $breedingPages]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ class StoreNewsBreedingRequest extends FormRequest
|
|||
'content' => ['required', 'string', new WysiwygLength(15, 15000)],
|
||||
'static_page_id' => [
|
||||
'required',
|
||||
Rule::enum(StaticPageType::class)->only(StaticPageType::getBreedingPages())
|
||||
Rule::exists('static_pages', 'id')->whereIn(
|
||||
'type',
|
||||
array_column(StaticPageType::getBreedingPages(), 'value')
|
||||
)
|
||||
],
|
||||
'picture_alt' => 'required_with:picture|between:3,255',
|
||||
'picture_title' => 'required_with:picture|between:3,255',
|
||||
|
|
|
|||
|
|
@ -224,20 +224,17 @@
|
|||
<legend>{{ str(trans_choice('validation.custom.static_page_id', 1))->ucfirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.tinyint-enum', [
|
||||
@include('bo.partials.inputs.bigint-foreign-id', [
|
||||
'id' => 'newsBreedingAssociatedPage',
|
||||
'name' => 'static_page_id',
|
||||
'model' => $newsBreedingModel ?? null,
|
||||
'associatedModels' => $breedingPages,
|
||||
'foreignLabel' => 'title',
|
||||
'label' => sprintf(
|
||||
'%s %s %s',
|
||||
str(trans_choice('validation.custom.static_page_id', 1))->ucfirst(),
|
||||
__('to'),
|
||||
trans_choice('models.classes.news_breeding', 1)),
|
||||
'name' => 'static_page_id',
|
||||
'model' => $newsBreedingModel ?? null,
|
||||
'required' => true,
|
||||
'value' => $newsBreedingModel->static_page_id,
|
||||
'associatedModels' => Arr::where(\App\Enums\StaticPageType::toArray(), function ($value, $key) {
|
||||
return \in_array($key, Arr::pluck(\App\Enums\StaticPageType::getBreedingPages(), 'name'));
|
||||
}),
|
||||
'helper' => __('crud.minicrud.select_entity', [
|
||||
'entity' => sprintf('une seule et unique %s', trans_choice('validation.custom.static_page_id', 1)),
|
||||
]),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue