i have this form, what i wanted to do is if the data for this id is exist, my submit button turn into update function.
i still use store data function for my controller because i didnt know how to do the logic.
public function store(Request $request)
{
$request->validate([
'title' => 'required',
'description' => 'required',
'category_page_id' => 'required',
]);
$seo = new Seo;
$seo->category_page_id = $request->input('category_page_id');
$seo->title = $request->input('title') ?? '';
$seo->description = $request->input('description');
$seo->save();
return back()->withStatus(__('SEO successfully updated.'));
}
and this is the form for my update function
<form method="post" action="{{ route('seo.update') }}" autocomplete="off">
#csrf
#method('put')
<h3 class="heading-small mb-4">{{ __('PAGE SEO') }}</h3>
#if (session('status'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('status') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
<div class="pl-lg-4">
<div class="form-group{{ $errors->has('category_page_id') ? ' has-danger' : '' }}">
<div class="form-group form-box">
<label for="category_page_id">Page</label>
<select class="form-control form-control-alternative{{ $errors->has('category_page_id') ? ' is-invalid' : '' }}" name="category_page_id">
#foreach ($categorypages->slice(0, 1) as $key => $value)
<option value="{{ $value->id }}" #if (old('category_page_id') == $value->id) {{ 'selected' }} #endif>{{ $value->name }}</option>
#endforeach
</select>
#error('category_page_id')
<small class="text-red">{{ $message }}</small>
#enderror
</div>
</div>
<div class="form-group{{ $errors->has('title') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-title">{{ __('SEO Title') }}</label>
<input type="text" name="title" id="input-title" class="form-control form-control-alternative{{ $errors->has('title') ? ' is-invalid' : '' }}" placeholder="{{ __('title') }}" value="{{ old('title', $seo->title) }}" required autofocus>
#if ($errors->has('title'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('title') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('description') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-description">{{ __('Description') }}</label>
<input type="description" name="description" id="input-description" class="form-control form-control-alternative{{ $errors->has('description') ? ' is-invalid' : '' }}" placeholder="{{ __('Description') }}" value="{{ old('description', $seo->description) }}" required>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
<div class="text-center">
<button type="submit" class="btn btn-success mt-4">{{ __('Save') }}</button>
</div>
</div>
</form>
what can i do to resolve my problem? is there any way to do this properly?
There are many ways to do
#if($seo_data != null) //here you can check the data is present or not
<form action="{{ route('seo_data.store')" method="post" >
#csrf
<input type="text" value="{{ isset($seo_data) ? $seo_data->title : '' }}">
<button type="submit" class="btn btn-primary">submit </button>
</form>
#else //if data is present then it goes to here
<form action="{{ route('seo_data.update',encrypt($seo_data->id))" method="post">
#csrf
#method('PATCH')
<input type="text" value="{{ isset($seo_data) ? $seo_data->title : '' }}">
<button type="submit" class="btn btn-primary">Update </button>
</form>
#endif
otherwise if you dont want to hit anther route then check it into store function
Related
)
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 :-)
hello my radiobutton disappeared after a laravel configuration they are used to modify user roles they worked for a moment and then disappeared
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Modifier <strong> {{ $user->name }}</strong></div>
<div class="card-body">
<form action="{{ route('admin.user.update', $user) }}" method="POST">
#csrf
#method('PATCH')
#foreach ($roles as $role)
<div class="form-group form-check">
#foreach ($user->roles as $userRole)
#if ($userRole->id == $role->id)
<input type="radio" class="form-check-input" name="roles[]" value="{{ $userRole }}" checked>
#else
<input type="radio" class="form-check-input" name="roles[]" value="{{ $userRole }}">
#endif
#endforeach
<label for="{{ $role->id }}" class="form-check-label">{{ $role->name }}</label>
</div>
#endforeach
<button type="submit" class="btn btn-primary">Modifier les roles</button>
</form>
You can use contains() with key and value defined:
The contains() method determines whether the collection contains a given item:
#foreach ($roles as $role)
<div class="form-group form-check">
<input type="radio" class="form-check-input" name="roles[]" value="{{ $role->id }}" {{ $user->roles->contains('id', $role->id) ? 'checked' : '' }} >
<label for="{{ $role->id }}" class="form-check-label">{{ $role->name }}</label>
</div>
#endforeach
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'?
I am trying to follow this template design:Template and I seem to be having some issue regarding the card height and padding with my current login page. Here is the code:
#section('content')
<div class="container">
<div class="card row h-100">
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="row">
<div class="col">
<img class="img-fluid rounded mx-auto d-block" src="{{asset('svg/MegaDeskLogo.svg')}}" alt="logo" />
</div>
<div class="col">
<h1>{{ __('Login') }}</h1>
<input id="email" type="email" placeholder="{{ __('E-Mail Address') }}" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>
{{ $errors->first('email') }}
</strong>
</span>
#endif
<input id="password" placeholder="{{ __('Password') }}" type="password" class="form-control {{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
#if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>
{{ $errors->first('password') }}
</strong>
</span>
#endif
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old( 'remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</div>
</form>
</div>
</div>
</div>
#endsection
Currently it's looking like: . I've tried reading several articles and reading the bootstrap documentation and still not able to find the answer. If anyone can offer any suggestions I would really appreciate it.
Make sure you're adding all the CSS and Javascript libraries and code you need for your card to look like the example, they are using more than just bootstrap.
Their CSS block:
Their Script block looks like:
i have a view named ('back.employee.detail') with an #includewhen('back.dossiers.create') into it.
my div for error is in 'back.employee.detail' :
<div class="alert {{ $type_alert }} alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria hidden="true">×</button>
<h4><i class="icon fa {{ $alert_icon }}"></i> Alert!</h4>
{{ $flash_message }}
</div>
my form is in my view 'back.dossiers.create' and inside i use $employee_detail :
<form method="POST" action="{{ route('create.document.employee.store', $employee_detail->id) }}" aria-label="{{ __('Create') }}">
#csrf
<div class="box-body">
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control {{ $errors->has('description') ? ' is-invalid' : '' }}"
name="description" id="description" value="{{ old('description') }}">
#if ($errors->has('description'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<label for="commentaire">Commentaire</label>
<input type="text" class="form-control{{ $errors->has('commentaire') ? ' is-invalid' : '' }}"
name="commentaire" id="commentaire" value="{{ old('commentaire') }}">
#if ($errors->has('commentaire'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('commentaire') }}</strong>
</span>
#endif
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
For validation error, i used to have that in my controller :
return back()->withErrors($validator)
->withInput()
->with('flash_message',$flash_message)
->with('type_alert',$type_alert)
->with('alert_icon',$alert_icon)
->with('type_crud',$type_crud)
->with('employee_detail',$employee_detail);
but the variable flash_message , type_alert... are into the parent view.
i want to update value for flash_message,type_alert,alert_icon,employee_detail and also type_crud and employee_detail but flash message has not been updated.
Do you have an idea how to do it ?
Thanks
Your question is't very clear to me.
Maybe this examples will help you a bit:
Pass data using includeWhen:
#includeWhen($boolean, 'view.name', ['some' => 'data'])
#include('view.name', ['some' => 'data'])
Hope this helps.
Gut luck:)