Its because you use @ before yield.
Try-
@if ($country->country_id == "@yield('country_id')" ) active @endif>
<i class="{{ strtolower($country->alpha2) }} flag"></i>
{{ $country->name }}</div>
@endforeach
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I would like to reuse my form fields in the create and update blades.
What i got so far is a:
create.blade.php edit.blade.php form.blade.php
edit.blade.php:
@extends('partner.form')
@section('name', $partner->name)
@section('phone', $partner->phone)
@section('partnerNumber', $partner->partner_number)
@section('street', $partner->street)
@section('zipcode', $partner->zipcode)
@section('city', $partner->city)
@section('country_id', $partner->country_id)
@section('country_region_id', $partner->country_region_id)
@section('insertTimestamp', $partner->insert_timestamp)
@section('insertUser' , $partner->insert_user)
form.blade.php:
for example:
<input type="text" name="street" placeholder="Adresse" value="@yield('street')">
like this i can populate my inputs if i render the edit.blade.php in my edit action, and leave them empty if i render the create.blade.php in the create action.
The problem i got is when i try to compare value, for example setting the value of a select/dropdown
as i cant compare the yielded values in IFs
@foreach($countries as $country)
<div class="item" data-value="{{$country->country_id}}"
@if ($country->country_id == @yield('country_id')) active @endif>
<i class="{{ strtolower($country->alpha2) }} flag"></i>{{ $country->name }}</div>
@endforeach
is there any other way to reuse forms and populate them?
I still use the Laravel Collective forms package, primarily for it’s form–model binding so I don’t have to pollute my Blade views with things like multiple @sections to populate form fields.
I’ll have a “form” template for whatever entity I’m editing, and then include that in both my create and edit views:
<!-- resources/views/admin/forms/product.blade.php -->
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
{{ Form::label('name') }}
<div class="form-controls">
{{ Form::text('name', null, ['class' => 'form-control', 'required', 'autofocus']) }}
</div>
</div>
<!-- And other fields -->
<!-- resources/views/admin/products/create.blade.php -->
@extends('admin.layout')
@section('content')
<h1>Add Product</h1>
{{ Form::open(['route' => 'admin.product.store']) }}
@include('admin.forms.product')
{{ Form::close() }}
@endsection
<!-- resources/views/admin/products/edit.blade.php -->
@extends('admin.layout')
@section('content')
<h1>Edit Product</h1>
{{ Form::model($product, ['route' => ['admin.product.update', $product], 'method' => 'PUT']) }}
@include('admin.forms.product')
{{ Form::close() }}
@endsection
Please or to participate in this conversation.