I want to remove this syntax for my form
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
{{ Form::label('name', 'Name') }}
{{ Form::text('name', null, array('class' => 'form-control')) }}
<br>
{!! $errors->first('name', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group {{ $errors->has('firstname') ? 'has-error' : '' }}">
{{ Form::label('firstname', 'Student Firstname') }}
{{ Form::textarea('firstname', null, array('class' => 'form-control')) }}
<br>
{!! $errors->first('firstname', '<span class="help-block">:message</span>') !!}
{{ Form::submit('Create Student', array('class' => 'btn btn-success btn-lg btn-block')) }}
{{ Form::close() }}
</div>
And put that syntax:
{{csrf_field()}}
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<fieldset class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
<label for="form-group-input-1">Name</label>
<input type="text" name="name" id="name" class="form-control" required="required" value="{{ old('name')}}"/>
{!! $errors->first('name', '<span class="help-block">:message</span>') !!}
</fieldset>
<fieldset class="form-group {{ $errors->has('firstname') ? 'has-error' : '' }}">
<label for="form-group-input-1">Firstname</label>
<input type="text" name="firstname" id="firstname" class="form-control" required="required" value="{{ old('firstname')}}"/>
{!! $errors->first('firstname', '<span class="help-block">:message</span>') !!}
</fieldset>
Is it a version problem? I am currently with version 5.4.13.
I have to update my version is that right?
If there is a problem it could be because the Form helper is not included in Laravel anymore since 5.0, as mentioned on this page.
The Form and HTML helpers have been deprecated in Laravel 5.0
Related
I'm using a Creative Tim template for my first Laravel project: Argon Pro 2 for Laravel, I can't get the form-switch field formatting to work for me using eloquent for my Crud. No problem with HTML. Any ideas?
With HTML (Blade):
<div class="form-check form-switch">
<input id="repetition" name="repetition" class="form-check-input" type="checkbox" id="CheckRepetition" value="{{ old('repetition') }}">
<label class="form-check-label" for="CheckRepetition">Activa para Repetición</label>
</div>
With Eloquent:
<div class="col-3 mb-3">
{{ Form::label('Tarea Repetitiva Checkbox *') }}
{{ Form::checkbox('repetition', $task->repetition, ['class' => 'form-switch ' .($errors->has('repetition') ? ' is-invalid' : '')]) }}
{!! $errors->first('repetition', '<div class="invalid-feedback">:message</div>') !!}
</div>
Thanks in advance ;)
Solved!
My code:
<div class="form-group">
<div class="col-2 mb-3">
{{ Form::label('Tarea Repetitiva') }}
{{ Form::hidden('repetition', '0') }}
<div class="form-check form-switch">
{{ Form::checkbox('repetition', '1', $task->repetition, ['class' => 'form-check-input' . ($errors->has('repetition') ? ' is-invalid' : '')]) }}
</div>
{!! $errors->first('repetition', '<div class="invalid-feedback">:message</div>') !!}
</div>
</div>
When I try to get a product and command it I get "Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into commande (name, familyname, quantity, mobile, ville, adresse, id_product, user_id, updated_at, created_at) values (?, ?, ?, ?, ?, ?, ?, ?, 2022-11-21 21:30:27, 2022-11-21 21:30:27))"
I am trying here to command a product where every product has a different user. I am using a foreign key in products table (user_id) and every command has a user to inspect it.
This is my function in the controller:
public function getProduct($id, Request $request)
{
$product = Product::find($id);
$commande = new AppCommande;
$commande->name = $request->input('name');
$commande->familyname = $request->input('familyname');
$commande->quantity = $request->input('quantity');
$commande->mobile = $request->input('mobile');
$commande->ville = $request->input('ville');
$commande->adresse = $request->input('adresse');
$commande->id_product = $request->input('id_product');
$commande->user_id = $request->input('id_user');
$commande->save();
return view('product', ['product' => $product], ['commande' => $commande]);
}
This is my route :
Route::get('/product/{id}', \[ 'uses' =\> 'CommandeUserController#getProduct', 'as' =\> 'product.single' \]);
and this is the view:
#extends('layouts.app')
#section('content')
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="{{ asset('uploads/product/'.$product->image) }}" width="90px" alt="image">
<div class="caption">
<h3> {{$product->name}} </h3>
<p class="discription"> {{$product->description}} </p>
<div class="clearfix">
<div class="pull-left price"/>$ {{$product->price}}</div>
{{-- Commander ce produit --}}
</div>
</div>
</div>
<div class="card">
<div class="card-header">
Create Commande
</div>
<div class="card-body">
<form action="{{ route("admin.commandes.store") }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
<label for="name">Name</label>
<input type="text" id="name" name="name" class="form-control" value="{{ old('name', isset($commande) ? $commande->name : '') }}">
#if($errors->has('name'))
<em class="invalid-feedback">
{{ $errors->first('name') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.name_helper') }}
</p>
</div>
<div class="form-group {{ $errors->has('familyname') ? 'has-error' : '' }}">
<label for="name">Family Name</label>
<input type="text" id="familyname" name="familyname" class="form-control" value="{{ old('familyname', isset($commande) ? $commande->familyname : '') }}">
#if($errors->has('name'))
<em class="invalid-feedback">
{{ $errors->first('name') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.name_helper') }}
</p>
</div>
<div class="form-group {{ $errors->has('mobile') ? 'has-error' : '' }}">
<label for="quantity">Mobile</label>
<input type="number" id="mobile" name="mobile" class="form-control" value="{{ old('mobile', isset($commande) ? $commande->mobile : '') }}" step="1">
#if($errors->has('mobile'))
<em class="invalid-feedback">
{{ $errors->first('mobile') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.price_helper') }}
</p>
</div>
<div class="form-group {{ $errors->has('quantity') ? 'has-error' : '' }}">
<label for="quantity">Quantity</label>
<input type="number" id="quantity" name="quantity" class="form-control" value="{{ old('quantity', isset($commande) ? $commande->quantity : '') }}" step="1">
#if($errors->has('price'))
<em class="invalid-feedback">
{{ $errors->first('price') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.price_helper') }}
</p>
</div>
<div class="form-group {{ $errors->has('ville') ? 'has-error' : '' }}">
<label for="ville">City</label>
<input type="text" id="ville" name="ville" class="form-control" value="{{ old('ville', isset($commande) ? $commande->familyname : '') }}">
#if($errors->has('ville'))
<em class="invalid-feedback">
{{ $errors->first('ville') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.name_helper') }}
</p>
</div>
<div class="form-group {{ $errors->has('adresse') ? 'has-error' : '' }}">
<label for="adress">Adresse</label>
<input type="text" id="adresse" name="adresse" class="form-control" value="{{ old('adresse', isset($commande) ? $commande->adresse : '') }}">
#if($errors->has('adresse'))
<em class="invalid-feedback">
{{ $errors->first('adresse') }}
</em>
#endif
<p class="helper-block">
{{ trans('global.product.fields.name_helper') }}
</p>
</div>
<input type="hidden" name="id_product" value=" {{ $product->id }}" />
<input type="hidden" name="user_id" value=" {{ $product->user_id }}" />
<input class="btn btn-danger" type="submit" value="{{ trans('global.save') }}">
</div>
</form>
</div>
</div>
#endsection
Hello I changed the getProduct() to and it works:
public function getProduct($id, Request $request)
{
$product = Product::find($id);
return view('product', ['product' => $product]);
}
and I used in the form a new store funtion for the command:
public function store(StoreProductRequest $request)
{
$user_id=auth()->user()->id;
$commande = new AppCommande();
$commande->name = $request->input('name');
$commande->familyname = $request->input('familyname');
$commande->quantity = $request->input('quantity');
$commande->mobile = $request->input('mobile');
$commande->ville = $request->input('ville');
$commande->adresse = $request->input('adresse');
$commande->id_product = $request->input('id_product');
$commande->user_id=$user_id;
$commande->save();
return redirect('/commandeuser/confirm')->with('status', 'commande ajoutée!');
}
Since I feel weird that your error message doesn't take any value from your request, try to add your $commande variable to a standard bracket '()' to your last model initiation.
$commande = new AppComande();
I´ve got this exception in my blade template. I made a relation between my two models (RegisteredCourses y User) and I can see it works in the rest of Blade´s template, except form.blade.php
Trying to get property 'user' of non-object (View: C:\laragon\www\hr-english\resources\views\registeredCourse\form.blade.php) (View: C:\laragon\www\hr-english\resources\views\registeredCourse\form.blade.php)
My idea is to show in my blade template the name of the user, but I need in the value of input the correspondant user_id.
I don´t what is the correct approach to this problem.
<div class="form-group {{ $errors->has('course_id') ? 'has-error' : '' }}">
<label for="course_id" class="col-md-2 control-label">Course</label>
<div class="col-md-10">
<select class="form-control" id="course_id" name="course_id">
<option value="" style="display: none;" {{ old('course_id', optional($registeredCourse)->course_id ?: '') == '' ? 'selected' : '' }} disabled selected>Select course</option>
#foreach ($courses as $key => $course)
<option value="{{ $key }}" {{ old('course_id', optional($registeredCourse)->course_id) == $key ? 'selected' : '' }}>
{{ $course }}
</option>
#endforeach
</select>
{!! $errors->first('course_id', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('user_id') ? 'has-error' : '' }}">
<label for="status_course" class="col-md-2 control-label">Name</label>
<div class="col-md-10">
<input class="form-control" name="user_id" type="text" id="user_id" value="{{ old('user_id', optional($registeredCourse->user->name)) }}" minlength="1" placeholder="Enter name here..."> <!--Problwm here-->
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('status_course') ? 'has-error' : '' }}">
<label for="status_course" class="col-md-2 control-label">Status Course</label>
<div class="col-md-10">
<input class="form-control" name="status_course" type="text" id="status_course" value="{{ old('status_course', optional($registeredCourse)->status_course) }}" minlength="1" placeholder="Enter status course here...">
{!! $errors->first('status_course', '<p class="help-block">:message</p>') !!}
</div>
</div>
Use the null coalescing operator: $registeredCourse->user->name ?? null instead of optional($registeredCourse->user->name) in your blade
UPS: Here's a demo showing how this works depending on whether $registeredCourse->user is set or not.
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 have 2 select box in this form, the first select box is done and works.
...But when I add the second select box, the error appears like the picture..
here's the code
This is the first select box - it works:
{{ Form::open(array('url' =>route('units.store'), 'method' => 'post' ))}}
<div class="form-group #if ($errors->has('brand_id')) has-error #endif">
<label>Brand Manufacture</label>
{{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }}
#if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> #endif
</div>
And this is the select that is not right:
<div class="form-group #if ($errors->has('model_id')) has-error #endif">
<label>Model Type</label>
{{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }}
#if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> #endif
</div>
And this is the whole code.
{{ Form::open(array('url' =>route('units.store'), 'method' => 'post' ))}}
<div class="form-group #if ($errors->has('brand_id')) has-error #endif">
<label>Brand Manufacture</label>
{{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }}
#if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('model_id')) has-error #endif">
<label>Model Type</label>
{{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }}
#if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('kva')) has-error #endif">
<label>kva</label>
<input name="kva" type="text" class="form-control w450" value="{{ Input::old('kva') }}">
#if ($errors->has('kva')) <p class="help-block">{{ $errors->first('kva') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('type')) has-error #endif">
<label>Type</label>
<select name="type" id="" class="form-control w450">
<option value="OPEN">OPEN</option>
<option value="CLOSE">CLOSE</option>
</select>
#if ($errors->has('type')) <p class="help-block">{{ $errors->first('type') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('sn')) has-error #endif">
<label>Serial Number</label>
<input name="sn" type="text" class="form-control w450" value="{{ Input::old('sn') }}">
#if ($errors->has('sn')) <p class="help-block">{{ $errors->first('sn') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('wbs_unit')) has-error #endif">
<label>WBS unit</label>
<input name="wbs_unit" type="text" class="form-control w450" value="{{ Input::old('wbs_unit') }}">
#if ($errors->has('wbs_unit')) <p class="help-block">{{ $errors->first('wbs_unit') }}</p> #endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-sm btn-primary">create</button>
</div>
{{ Form::close() }}
I can't post any image :(
so help me..please
Make sure you're pulling data from the database in the correct format for the select box. It should be an associative array with the key being the database ID and the value being the string you want to show in the dropdown. Here's an example.
$brands = Brand::lists('name', 'id');
// Example: ['1' => 'Adidas', '2' => 'Nike', '3' => 'New Balance;];
{{ Form::select('brand_id', $brands) }}
Also, you can simplify your error class using a ternary statement, something like this.
<div class="form-group {{ $errors->has('brand_id') ? 'has-error' : null }}">