Update user data by user profile page - laravel

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'?

Related

I get "SQLSTATE[23000]: Integrity constraint violation" when I try to add a command

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();

if data exist submit button turn into update function (Laravel)

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

Form checkbox input array gets flooded with textarea input

)
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 :-)

button disappeared after configuration laravel

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

How to adjust card height with Bootstrap in Laravel 5

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:

Resources