Good morning,
I want build a multistep form in Laravel and I discover a lot of tutorial on Youtube to make this but In my form, I use a Foreach because I build a exam system and I display Question and Response with foreach.
This is my Code :
<form method="POST" action="{{ route('stagiaire.session.test.store',['id'=>$eval->id]) }}">
#csrf
#foreach($questioncat as $category)
<div class="card mb-3">
<div class="card-header">{{ $category->nom }}</div>
<div class="card-body">
#foreach($category->getQuestion as $question)
<div class="card #if(!$loop->last)mb-3 #endif">
<div class="card-header">{{ $question->question_text }}</div>
<div class="card-body">
<input type="hidden" name="questions[{{ $question->id }}]" value="">
#foreach($question->reponse as $option)
<div class="form-check">
<input class="form-check-input" type="radio" name="questions[{{ $question->id }}]" id="option-{{ $option->id }}" value="{{ $option->id }}"#if(old("questions.$question->id") == $option->id) checked #endif>
<label class="form-check-label" for="option-{{ $option->id }}">
{{ $option->option_text }}
</label>
</div>
#endforeach
#if($errors->has("questions.$question->id"))
<span style="margin-top: .25rem; font-size: 80%; color: #e3342f;" role="alert">
<strong>{{ $errors->first("questions.$question->id") }}</strong>
</span>
#endif
</div>
</div>
#endforeach
</div>
</div>
#endforeach
<div class="form-group row mb-0">
<div class="col-md-6">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
So my question, is it possible to build a multistep form with foreach?
Thanks
I am at the thinking stage
How can I export the data when I open a foreach in the application I developed in Laravel. For example, I want to filter after some id sync.
Blade/View
#foreach ($parts as $item)
#foreach ($country->getPerson ?? [] as $person)
#if ($country->id == $person->country_id)
#endif
#endforeach
#if ($loop->iteration == $person->part_id)
#continue
#endif
<div class="col-sm-6 col-lg-4">
<div class="service-item my-3">
<div class="service-wrapper m-0 bg-white">
<div class="service-content mt-3">
<h5 class="mb-3"> {{ $item->name }}</h5>
<a data-bs-toggle="modal" data-bs- target="#service1"
href="#" class="text-primary">
Alert!
<i class="fas fa-angle-right ms-2"> </i>
</a>
<br> <br>
<form class="call-to-action-form m-auto" action="{{ route('add.person') }}"
enctype="multipart/form-data" method="POST">
#csrf
<div class="input-group">
<input type="text" class="form-control" name="name"
placeholder="Adınız Soyadınız" required> <br>
<input type="text" class="form- control" name="email"
placeholder="E-Mail Adresiniz" required>
</div>
<input type="hidden" name="country_id" value="{{ $country->id }}" required>
<input type="hidden" name="part_id" value="{{ $item->part_id }}" required>
<br>
<button class="btn btn-success" type="submit">Cüzü Al
</button>
</form>
</div>
</div>
</div>
#endforeach
I want to return it here.
what I want to do is
{{person->part_id}}
by assigning its value outside the foreach
#if ($loop->iteration == $person->part_id)
#continue
#endif
My associated models run regularly. Now I need to filter the ids corresponding to my person table in my part table. The code sequence I shared above only takes the latest id. I cannot get other corresponding ids, so it only filters once.
I have a form with a filter and a submit button. I would like to display a pdf in an embed tag on the same page with the filter fields used when generating the pdf with Dompdf. Thanks in advance.
here is the form :
#section('content')
<!-- Your html goes here -->
<div class='panel panel-default'>
<div class='panel-heading'>Customer Statement</div>
<div class='panel-body'>
<form method='get' action="{{ route('getStatement') }}" id="statementForm">
#csrf
<div class="row">
<div class='col-sm-6 form-group'>
<div class="form-group col-6">
<label for="start_date"><strong>Start Date</strong></label>
<input type="date" required name="start_date" value="{{ date('Y-m-d') }}"
class="form-control" id="start_date">
</div>
</div>
<div class='col-sm-6 form-group'>
<div class="form-group col-6">
<label for="end_date"><strong>End Date</strong></label>
<input type="date" required name="end_date" value="{{ date('Y-m-d') }}"
class="form-control" id="end_date">
</div>
</div>
</div>
<div class='col-sm-12 form-group'>
<label> Customers :</label>
<select style="font-size: 12px; width:100%" id="customer_id" name="customer_id"
class="select2 mb-2 select2-multiple">
<option value=''> Choose </option>
#if ($customers)
#foreach ($customers as $item)
#php $selected = ''; #endphp
#if (isset($customerdirect) == $item->id)
#php $selected = 'selected'; #endphp
#endif
<option data-name="{{ $item->name }}" value='{{ $item->id }}' {{ $selected }}>
{{ $item->name }} </option>
#endforeach
#endif
</select>
</div>
</div>
<div class='panel-footer'>
<input type='submit' class='btn btn-success' value='Generate'/>
</div>
</form>
</div>
#endsection
the code in controller
public function getStatement(Request $request)
{
$pdf = PDF::loadView('customerslocations::customerstatementpdf');
return $pdf->stream();
}
)
I have been struggling with a form for my Laravel App....
I have 3 fields which are checkboxes and therefore is getting POSTed as arrays and then I have a textarea field and somehow SOMETIMES one of the 3 checkbox inputs get flooded with data from the textarea input field... It is very weird and only happens sometime and therefore I get a data to long truncated error in the database...
But I DD the input at the $request level and can see already there the array from the checkbox is flooded with the data from the textarea field... I can not wrap my head around why this is, as it's only sometimes...
And I can even get the error and go back a page in the browser and submit again with all the same data and then it can be working.. WHAT can cause this weird behavioer
This is my Laravel blade where the form is
#extends('layouts.app')
#section('head')
#endsection
#section('content')
#php
// dd($errors);
#endphp
<h2 class="page-title">Opret Artist Side</h2>
<div class="artist-box">
<form class="formgrid" method="POST" action="{{ route('artist.store') }}">
#csrf
<div class="formleft">
<label for="artist_name" class="label">Artist navn</label>
<input type="text" id="artist_name" name="artist_name" class="formitem #error('artist_name') is-invalid #enderror" value="{{ old('artist_name', $post->artist_name ?? null) }}" />
#error('artist_name')
<div class="invalid-feedback">
#foreach($errors->get('artist_name') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="artist_name_help">Jeres band/artist navn. <span class="text-danger">OBS! Kan IKKE ændres</span></small>
#enderror
</div>
<div class="formright">
<label for="contact_person" class="label">Kontakt person</label>
<input type="text" name="contact_person" id="contact_person" class="formitem #error('contact_person') is-invalid #enderror" value="{{ old('contact_person', $post->content ?? null) }}" />
#error('contact_person')
<div class="invalid-feedback">
#foreach($errors->get('contact_person') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="contact_person_help">Kontakt persons navn</small>
#enderror
</div>
<div class="formleft">
<label for="email" class="label">Email</label>
<input type="text" name="email" id="email" class="formitem #error('email') is-invalid #enderror" value="{{ old('email', $post->email ?? null) }}" />
#error('email')
<div class="invalid-feedback">
#foreach($errors->get('email') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="email_help">Kontakt email</small>
#enderror
</div>
<div class="formright">
<label for="phone" class="label">Tlf nummer</label>
<input type="text" name="phone" id="phone" class="formitem #error('phone') is-invalid #enderror" value="{{ old('phone', $post->phone ?? null) }}" />
#error('phone')
<div class="invalid-feedback">
#foreach($errors->get('phone') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="phone_help">Kontakt tlf nummer</small>
#enderror
</div>
<div class="formleft">
<label for="hometown" class="label">Hjemby</label>
<input type="text" name="hometown" id="hometown" class="formitem #error('hometown') is-invalid #enderror" value="{{ old('hometown', $post->hometown ?? null) }}" />
#error('hometown')
<div class="invalid-feedback">
#foreach($errors->get('hometown') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="hometown_help">Jeres Hjemby</small>
#enderror
</div>
<div class="formright">
<label for="category" class="label">Kategori</label>
<select name="category" id="category" class="formitem #error('category') is-invalid #enderror">
{{-- Show a non selectable if with info of none selected --}}
#if(old('category') === null)
<option disabled="disabled" selected value="null">Vælg en kategori</option>
#endif
#foreach($categories as $category)
<option #if(old('category') !== null && old('category') == $category->id) selected #endif value="{{ $category->id }}"
>{{ $category->artist_category }}</option>
#endforeach
</select>
#error('category')
<div class="invalid-feedback">
#foreach($errors->get('category') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Hvilken kategori hører i under</small>
#enderror
</div>
<div class="formfull">
<label for="budget" class="label">Budget i spiller for</label>
<ul class="ks-cboxtags">
#foreach($budgets as $budget)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('budget') !== null && in_array($budget->id,old('budget'))) checked #endif
type="checkbox" name="budget[]" id="budget{{ $budget->id }}" class="form-check-input #error('budget') is-invalid #enderror" value="{{ $budget->id }}" />
<label class="form-check-label" for="budget{{ $budget->id }}">{{ $budget->artist_budget }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('budget')
<div class="invalid-feedback d-block">
#foreach($errors->get('budget') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="budget_help">Vælg hvilket budget i optræder for, gerne flere</small>
#enderror
</div>
{{-- --}}
<div class="formfull">
<label for="genres" class="label">Genre</label>
<ul class="ks-cboxtags">
#foreach($genres as $genre)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('genres') !== null && in_array($genre->id,old('genres'))) checked #endif
type="checkbox" name="genres[]" id="genres{{ $genre->id }}" value="{{ $genre->id }}" class="form-check-input #error('genres') is-invalid #enderror" />
<label class="form-check-label" for="genres{{ $genre->id }}">{{ $genre->genre }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('genres')
<div class="invalid-feedback d-block">
#foreach($errors->get('genres') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Hvike genrer hører i under</small>
#enderror
</div>
{{-- --}}
<div class="formfull">
<label for="area" class="label">Områder hvor i optræder</label>
<ul class="ks-cboxtags">
#foreach($areas as $area)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('area') !== null && in_array($area->id,old('area'))) checked #endif
type="checkbox" name="area[]" id="area{{ $area->id }}" value="{{ $area->id }}" class="form-check-input #error('area') is-invalid #enderror" />
<label class="form-check-label" for="area{{ $area->id }}">{{ $area->artist_area }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('area')
<div class="invalid-feedback d-block">
#foreach($errors->get('area') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Vælg hvilke områder i optræder i</small>
#enderror
</div>
<div class="formleft">
<label for="desc" class="label">Beskriv jer selv</label>
<textarea name="description" id="description" class="formitem #error('description') is-invalid #enderror">{{ old('description', $post->description ?? null) }}</textarea>
{{-- <input id="description" value="{{ old('description', $post->description ?? null) }}" class="form-control #error('description') is-invalid #enderror" name="description" type="hidden">
#trix(\App\ArtistPage::class, 'trixinput',
[
'id' => 'description',
// 'class' => 'form-control',
'hideTools' => ['file-tools'],
'hideButtonIcons' => ['attach', 'link', 'code', 'strike', 'heading-1']
]) --}}
{{-- <input id="desc" value="{{ old('description', $post->description ?? null) }}" type="hidden" name="description">
<trix-editor input="desc" class="#error('description') is-invalid #enderror"></trix-editor> --}}
#error('description')
<div class="invalid-feedback">
#foreach($errors->get('description') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="description_help">Giv en god beskrivelse af jer selv og hvad i tilbyder<br>
Tilladte tags er <strong>{{ '<br><b><i><li><ul><ol><hr><strong><p>' }}</strong>
</small>
#enderror
</div>
<button type="submit" class="btn btn-primary">Opret</button>
</form>
</div>
#endsection
See also this image of the DD dump on the $request
Hmmmm Think I figured it out :-)
But it has been such a sporadic bug so I'm not sure yet... But seems like it has gone away :-)
Seems like it was this value line on each field I have gotten messed up
The value line structure on the input fields I had was
value="{{ old('artist_name', $post->artist_name ?? null) }}"
And it should be
value="{{ old('artist_name') ?? $post->artist_name ?? null }}"
Dont know why I ended up with such an obscure Value part on every input field :-)
But sometimes the eyes just gets blind on code :-)
I am new in Laravel. I have done a custom profile page and try to update the value by each user. Now i am trying like this
Edit page
#extends('layouts.admin')
#section('content')
<?php $user = auth()->user(); ?>
<div class="card">
<div class="card-header">
{{ trans('global.edit') }} {{ trans('cruds.user.title_singular') }}
</div>
<div class="card-body">
<form action="{{ route('admin.users.updateprofile', $user->id) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('POST')
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('name') ? 'has-error' : '' }}">
<label for="name">{{ trans('cruds.user.fields.name') }}*</label>
<input type="text" id="name" name="name" class="form-control" value="{{ old('name', isset($user) ? $user->name : '') }}" required>
#if($errors->has('name'))
<em class="invalid-feedback">
{{ $errors->first('name') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.name_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('email') ? 'has-error' : '' }}">
<label for="email">{{ trans('cruds.user.fields.email') }}*</label>
<input type="email" id="email" name="email" class="form-control" value="{{ old('email', isset($user) ? $user->email : '') }}" required>
#if($errors->has('email'))
<em class="invalid-feedback">
{{ $errors->first('email') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.email_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('address') ? 'has-error' : '' }}">
<label for="address">{{ trans('cruds.user.fields.address') }}*</label>
<input type="text" id="address" name="address" class="form-control" value="{{ old('address', isset($user) ? $user->address : '') }}" required>
#if($errors->has('address'))
<em class="invalid-feedback">
{{ $errors->first('address') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.address_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('landmark') ? 'has-error' : '' }}">
<label for="landmark">{{ trans('cruds.user.fields.landmark') }}*</label>
<input type="text" id="landmark" name="landmark" class="form-control" value="{{ old('landmark', isset($user) ? $user->landmark : '') }}" required>
#if($errors->has('landmark'))
<em class="invalid-feedback">
{{ $errors->first('landmark') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.landmark_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('locality') ? 'has-error' : '' }}">
<label for="locality">{{ trans('cruds.user.fields.locality') }}*</label>
<input type="text" id="locality" name="locality" class="form-control" value="{{ old('locality', isset($user) ? $user->locality : '') }}" required>
#if($errors->has('locality'))
<em class="invalid-feedback">
{{ $errors->first('locality') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.locality_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('city') ? 'has-error' : '' }}">
<label for="city">{{ trans('cruds.user.fields.city') }}*</label>
<input type="text" id="city" name="city" class="form-control" value="{{ old('city', isset($user) ? $user->city : '') }}" required>
#if($errors->has('city'))
<em class="invalid-feedback">
{{ $errors->first('city') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.city_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('pin') ? 'has-error' : '' }}">
<label for="pin">{{ trans('cruds.user.fields.pin') }}*</label>
<input type="text" id="pin" name="pin" class="form-control" value="{{ old('pin', isset($user) ? $user->pin : '') }}" required>
#if($errors->has('pin'))
<em class="invalid-feedback">
{{ $errors->first('pin') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.pin_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('country') ? 'has-error' : '' }}">
<label for="country">{{ trans('cruds.user.fields.country') }}*</label>
<input type="text" id="country" name="country" class="form-control" value="{{ old('country', isset($user) ? $user->country : '') }}" required>
#if($errors->has('country'))
<em class="invalid-feedback">
{{ $errors->first('country') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.country_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('principalname') ? 'has-error' : '' }}">
<label for="principalname">{{ trans('cruds.user.fields.principalname') }}*</label>
<input type="text" id="principalname" name="principalname" class="form-control" value="{{ old('principalname', isset($user) ? $user->principalname : '') }}" required>
#if($errors->has('principalname'))
<em class="invalid-feedback">
{{ $errors->first('principalname') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.principalname_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('pocname') ? 'has-error' : '' }}">
<label for="pocname">{{ trans('cruds.user.fields.pocname') }}*</label>
<input type="text" id="pocname" name="pocname" class="form-control" value="{{ old('pocname', isset($user) ? $user->pocname : '') }}" required>
#if($errors->has('pocname'))
<em class="invalid-feedback">
{{ $errors->first('pocname') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.pocname_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('pocnum_one') ? 'has-error' : '' }}">
<label for="pocnum_one">{{ trans('cruds.user.fields.pocnum_one') }}*</label>
<input type="text" id="pocnum_one" name="pocnum_one" class="form-control" value="{{ old('pocnum_one', isset($user) ? $user->pocnum_one : '') }}" required>
#if($errors->has('pocnum_one'))
<em class="invalid-feedback">
{{ $errors->first('pocnum_one') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.pocnum_one_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('pocnum_two') ? 'has-error' : '' }}">
<label for="pocnum_two">{{ trans('cruds.user.fields.pocnum_two') }}*</label>
<input type="text" id="pocnum_two" name="pocnum_two" class="form-control" value="{{ old('pocnum_two', isset($user) ? $user->pocnum_two : '') }}" required>
#if($errors->has('pocnum_two'))
<em class="invalid-feedback">
{{ $errors->first('pocnum_two') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.pocnum_two_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('emailid') ? 'has-error' : '' }}">
<label for="emailid">{{ trans('cruds.user.fields.emailid') }}*</label>
<input type="text" id="emailid" name="emailid" class="form-control" value="{{ old('emailid', isset($user) ? $user->emailid : '') }}" required>
#if($errors->has('emailid'))
<em class="invalid-feedback">
{{ $errors->first('emailid') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.emailid_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('registered_year') ? 'has-error' : '' }}">
<label for="registered_year">{{ trans('cruds.user.fields.registered_year') }}*</label>
<input type="text" id="registered_year" name="registered_year" class="form-control" value="{{ old('registered_year', isset($user) ? $user->registered_year : '') }}" required>
#if($errors->has('registered_year'))
<em class="invalid-feedback">
{{ $errors->first('registered_year') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.registered_year_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('healthid') ? 'has-error' : '' }}">
<label for="healthid">{{ trans('cruds.user.fields.healthid') }}*</label>
<input type="text" id="healthid" name="healthid" class="form-control" value="{{ old('healthid', isset($user) ? $user->healthid : '') }}" required>
#if($errors->has('healthid'))
<em class="invalid-feedback">
{{ $errors->first('healthid') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.healthid_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('totalstaff') ? 'has-error' : '' }}">
<label for="totalstaff">{{ trans('cruds.user.fields.totalstaff') }}*</label>
<input type="text" id="totalstaff" name="totalstaff" class="form-control" value="{{ old('totalstaff', isset($user) ? $user->totalstaff : '') }}" required>
#if($errors->has('totalstaff'))
<em class="invalid-feedback">
{{ $errors->first('totalstaff') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.totalstaff_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12">
<label for="exampleFormControlSelect1">Select School</label>
<select class="form-control" name="school_name" id="exampleFormControlSelect1">
<option> Select School</option>
<?php
$schools = DB::table('schools')->get();
?>
#foreach($schools as $school)
<option value="{{$school->name}}">{{$school->name}}</option>
#endforeach
</select>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('school_branch') ? 'has-error' : '' }}">
<label for="school_branch">{{ trans('cruds.user.fields.school_branch') }}*</label>
<input type="text" id="school_branch" name="school_branch" class="form-control" value="{{ old('school_branch', isset($user) ? $user->school_branch : '') }}" required>
#if($errors->has('school_branch'))
<em class="invalid-feedback">
{{ $errors->first('school_branch') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.school_branch_helper') }}
</p>
</div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('password') ? 'has-error' : '' }}">
<label for="password">{{ trans('cruds.user.fields.password') }}</label>
<input type="password" id="password" name="password" class="form-control" required>
#if($errors->has('password'))
<em class="invalid-feedback">
{{ $errors->first('password') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.password_helper') }}
</p>
</div>
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12 {{ $errors->has('roles') ? 'has-error' : '' }}">
<label for="roles">{{ trans('cruds.user.fields.roles') }}*</label>
<select name="roles[]" id="roles" class="form-control select2" multiple="multiple" required readonly>
#foreach($roles as $id => $roles)
<option value="{{ $id }}" {{ (in_array($id, old('roles', [])) || isset($user) && $user->roles()->pluck('name', 'id')->contains($id)) ? 'selected' : '' }}>{{ $roles }}</option>
#endforeach
</select>
#if($errors->has('roles'))
<em class="invalid-feedback">
{{ $errors->first('roles') }}
</em>
#endif
<p class="helper-block">
{{ trans('cruds.user.fields.roles_helper') }}
</p>
</div>
<div>
</div>
<div class="row">
<div class="form-group col-xl-6 col-lg-6 col-md-6 col-sm-12">
<input class="btn btn-danger" type="submit" value="{{ trans('global.save') }}">
</div>
</div>
</form>
</div>
</div>
#endsection
For route i have written like this
Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('/home', 'HomeController#index')->name('home');
Route::resource('permissions', 'Admin\PermissionsController');
Route::post('permissions_mass_destroy', 'Admin\PermissionsController#massDestroy')->name('permissions.mass_destroy');
Route::resource('roles', 'Admin\RolesController');
Route::post('roles_mass_destroy', 'Admin\RolesController#massDestroy')->name('roles.mass_destroy');
Route::resource('users', 'Admin\UsersController');
Route::get('/pages', 'PageController#index');
Route::get('/pages/create', 'PageController#create');
Route::post('/pages/create', 'PageController#store');
Route::get('/pages/edit/{id}', 'PageController#edit');
Route::post('/home/edit/{id}', 'PageController#update');
Route::get('/schools', 'SchoolController#index');
Route::get('/schools/create', 'SchoolController#create');
Route::post('/schools/create', 'SchoolController#store');
Route::get('/schools/edit/{id}', 'SchoolController#edit');
Route::post('/schools/edit/{id}', 'SchoolController#update');
Route::post('users_mass_destroy', 'Admin\UsersController#massDestroy')->name('users.mass_destroy');
Route::get('/user/edit/{id}', 'Admin\UsersController#editprofile')->name('users.editprofile');
Route::post('/user/edit/{id}', 'Admin\UsersController#updateprofile')->name('users.updateprofile');
});
And for the Controller,i have written like this
public function editprofile(User $user)
{
$roles = Role::get()->pluck('name', 'name');
return view('admin.users.editprofile', compact('user', 'roles'));
}
And the Update profile method is like this
public function updateprofile(UpdateUsersRequest $request, User $user)
{
$user->update($request->all());
$roles = $request->input('roles') ? $request->input('roles') : [];
$user->syncRoles($roles);
return redirect()->route('admin.users.editprofile');
}
Now i am trying to update the user values which is entered in the edit form. But now it is showing me this error.
Missing required parameters for [Route: admin.users.editprofile] [URI: admin/user/edit/{id}].
Can you please help me to get the error and understand this. Thanks in advance.
you are redirecting to the edit profile page after updating. your edit profile route requires a parameter which is missing. so pass the parameter with the route
public function updateprofile(UpdateUsersRequest $request, User $user)
{
$user->update($request->all());
$roles = $request->input('roles') ? $request->input('roles') : [];
$user->syncRoles($roles);
return redirect()->route('admin.users.editprofile',$user->id);
}
Update
You have naming issues with your routes!
here the route is 'admin.users.updateprofile'
<form action="{{ route('admin.users.updateprofile', $user->id) }}" method="POST" enctype="multipart/form-data">
but your routes say 'users.updateprofile'
Route::post('/user/edit/{id}', 'Admin\UsersController#updateprofile')->name('users.updateprofile');
So you are not entering the expected endpoint.
The error is in this line
return redirect()->route('admin.users.editprofile');
where you don't pass the {íd} parameter. Change to
return redirect()->route('admin.users.editprofile', ['id' => $user->id]);
See more in the docs.
Also I can't see all your routes, but should 'admin.users.editprofile' not be 'users.editprofile'?