Laravel update function doesn't work and no error shown - php
I'm trying to update my database record with simple query in laravel controller.
This is my code,
DB::table('calender_events')->where('id', '=', '1')->update(
array(
'title' => $request->title,
)
);
form
<form id="addEventForm" method="post" action="{{ route('editEvent.store') }}" autocomplete="off">
#csrf
<div class="pl-lg-4">
<div class="form-group{{ $errors->has('title') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-title">{{ __('Title') }}</label>
<div class="row">
<div class="col">
<input type="text" name="title" id="input-title" class="form-control form-control-alternative{{ $errors->has('title') ? ' is-invalid' : '' }}" placeholder="{{ __('Title') }}" value="{{ $old_event['title'] }}" required autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Title: {{ $old_event['title'] }}</p>
</div>
</div>
#if ($errors->has('title'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('title') }}</strong>
</span>
#endif
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary mt-4">{{ __('Save') }}</button>
</div>
</div>
</form>
when I click save button it redirect to home page as expected , but db doesn't get updated.
also I used insert and select queries without any error.
and yes,there is a record in database with id=1.
please help!
You should have to write the code like this
DB::table('calender_events')->where('id',1)->update(
array(
'title' => $request->title,
)
);
This is the working code I finally come up with,
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class EditUserController extends Controller
{
/**
* Update the specified user in storage
*
* #param \App\Http\Request $request
* #return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request)
{
$image = $request->file('avatar');
if($image!=null){
$avatar_name = $request->get('NIC').'.'.$image->getClientOriginalExtension();
$folder = '/uploads/avatars/';
// $filePath = $folder . $avatar_name;
$this->uploadOne($image, $folder, 'public', $avatar_name);
}else{
$avatar_name = null;
}
DB::table('users')->where('id', '=', $request->user_id_)->update(
array(
'avatar_id' => $avatar_name,
'name'=>$request->name,
'NIC'=>$request->NIC,
'email'=>$request->email,
'current_job_position'=>$request->current_job_position,
'birthday'=>$request->birthday,
'anniversary'=>$request->anniversary,
'phone_home'=>$request->phone_home,
'phone_mobile'=>$request->phone_mobile,
'address_permanent'=>$request->address_permanent,
'address_temporary'=>$request->address_temporary,
'branch'=>$request->branch,
'bank'=>$request->bank,
'bank_number'=>$request->bank_number,
'user_role'=>$request->user_role,
'supervisor_manager'=>$request->supervisor_manager,
'next_kin_name'=>$request->next_kin_name,
'next_kin_occupation'=>$request->next_kin_occupation,
'next_kin_address'=>$request->next_kin_address,
'next_kin_office_address'=>$request->next_kin_office_address,
'next_kin_phone_mobile'=>$request->next_kin_phone_mobile,
'next_kin_phone_home'=>$request->next_kin_phone_home,
'updated_at'=>now()
)
);
return redirect()->route('user.index')->withStatus(__('User successfully updated.'));
}
/**
* Store a newly created user in storage
*
* #param \App\Http\Request $request
* #return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
$image = $request->file('avatar');
$pass = Hash::make($request->password);
if($image!=null){
$avatar_name = $request->get('NIC').'.'.$image->getClientOriginalExtension();
$folder = '/uploads/avatars/';
// $filePath = $folder . $avatar_name;
$this->uploadOne($image, $folder, 'public', $avatar_name);
DB::table('users')->insert([
[
'avatar_id' => $avatar_name,
'name'=>$request->name,
'NIC'=>$request->NIC,
'email'=>$request->email,
'password'=>$pass,
'current_job_position'=>$request->current_job_position,
'birthday'=>$request->birthday,
'anniversary'=>$request->anniversary,
'phone_home'=>$request->phone_home,
'phone_mobile'=>$request->phone_mobile,
'address_permanent'=>$request->address_permanent,
'address_temporary'=>$request->address_temporary,
'branch'=>$request->branch,
'bank'=>$request->bank,
'bank_number'=>$request->bank_number,
'user_role'=>$request->user_role,
'supervisor_manager'=>$request->supervisor_manager,
'next_kin_name'=>$request->next_kin_name,
'next_kin_occupation'=>$request->next_kin_occupation,
'next_kin_address'=>$request->next_kin_address,
'next_kin_office_address'=>$request->next_kin_office_address,
'next_kin_phone_mobile'=>$request->next_kin_phone_mobile,
'next_kin_phone_home'=>$request->next_kin_phone_home,
'created_at'=>now(),
],
]);
}else{
DB::table('users')->insert([
[
'name'=>$request->name,
'NIC'=>$request->NIC,
'email'=>$request->email,
'password'=>$pass,
'current_job_position'=>$request->current_job_position,
'birthday'=>$request->birthday,
'anniversary'=>$request->anniversary,
'phone_home'=>$request->phone_home,
'phone_mobile'=>$request->phone_mobile,
'address_permanent'=>$request->address_permanent,
'address_temporary'=>$request->address_temporary,
'branch'=>$request->branch,
'bank'=>$request->bank,
'bank_number'=>$request->bank_number,
'user_role'=>$request->user_role,
'supervisor_manager'=>$request->supervisor_manager,
'next_kin_name'=>$request->next_kin_name,
'next_kin_occupation'=>$request->next_kin_occupation,
'next_kin_address'=>$request->next_kin_address,
'next_kin_office_address'=>$request->next_kin_office_address,
'next_kin_phone_mobile'=>$request->next_kin_phone_mobile,
'next_kin_phone_home'=>$request->next_kin_phone_home,
'created_at'=>now(),
],
]);
}
return redirect()->route('user.index')->withStatus(__('User successfully created.'));
}
public function uploadOne(UploadedFile $uploadedFile, $folder = null, $disk = 'public', $filename = null)
{
$name = !is_null($filename) ? $filename : Str::random(25);
$path =storage_path('uploads/avatars/'.$filename.'');
if( Storage::exists($path)){
Storage::disk('public')->delete('uploads/avatars/'.$filename.'');
}
$file = $uploadedFile->storeAs($folder, $name, $disk);
return $file;
}
}
#extends('layouts.app')
#section('content')
#include('layouts.headers.cards')
<div class="container-fluid mt--7">
<div class="row">
<div class="col-xl-12 mb-5 mb-xl-0">
<div class="card bg-white shadow">
<div class="card-body">
<form id="addEventForm" method="post" action="{{ route('editEvent.store') }}" autocomplete="off">
#csrf
<div class="pl-lg-4">
<input type="number" name="eventId" id="input-eventId" value="{{ $old_event['id'] }}" style="visibility:hidden;">
<div class="form-group{{ $errors->has('title') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-title">{{ __('Title') }}</label>
<div class="row">
<div class="col">
<input type="text" name="title" id="input-title" class="form-control form-control-alternative{{ $errors->has('title') ? ' is-invalid' : '' }}" placeholder="{{ __('Title') }}" value="{{ $old_event['title'] }}" required autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Title: {{ $old_event['title'] }}</p>
</div>
</div>
#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>
<div class="row">
<div class="col">
<input type="text" name="description" id="input-description" class="form-control form-control-alternative{{ $errors->has('description') ? ' is-invalid' : '' }}" placeholder="{{ __('Description') }}" value="{{ $old_event['description'] }}" required autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Description: {{ $old_event['description'] }}</p>
</div>
</div>
#if ($errors->has('description'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('startTime') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-startTime">{{ __('Start Time') }}</label>
<div class="row">
<div class="col">
<input type="time" name="startTime" id="input-startTime" class="form-control form-control-alternative{{ $errors->has('startTime') ? ' is-invalid' : '' }}" placeholder="{{ __('Start Time') }}" value="{{ old('startTime') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Start time: {{ $old_event['startTime'] }}</p>
</div>
</div>
#if ($errors->has('startTime'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('startTime') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('endTime') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-endTime">{{ __('End Time') }}</label>
<div class="row">
<div class="col">
<input type="time" name="endTime" id="input-endTime" class="form-control form-control-alternative{{ $errors->has('endTime') ? ' is-invalid' : '' }}" placeholder="{{ __('End Time') }}" value="{{ old('endTime') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current End time: {{ $old_event['endTime'] }}</p>
</div>
</div>
#if ($errors->has('endTime'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('endTime') }}</strong>
</span>
#endif
</div>
<fieldset style="border:groove;padding:5px;">
<legend style="font-size:12px;">      One day event (set this values only for one day event)</legend>
<div class="form-group{{ $errors->has('start') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-start">{{ __('Start') }}</label>
<div class="row">
<div class="col">
<input type="date" name="start" id="input-start" class="form-control form-control-alternative{{ $errors->has('start') ? ' is-invalid' : '' }}" placeholder="{{ __('Start') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Start date: {{ $old_event['start'] }}</p>
</div>
</div>
#if ($errors->has('start'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('start') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('end') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-end">{{ __('End') }}</label>
<div class="row">
<div class="col">
<input type="date" name="end" id="input-end" class="form-control form-control-alternative{{ $errors->has('end') ? ' is-invalid' : '' }}" placeholder="{{ __('End') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current End date: {{ $old_event['end'] }}</p>
</div>
</div>
#if ($errors->has('end'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('end') }}</strong>
</span>
#endif
</div>
</fieldset>
<fieldset style="border:groove;padding:5px;">
<legend style="font-size:12px;">      Recurring event (set this values if event is recurring)</legend>
<div class="form-group{{ $errors->has('startRecur') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-startRecur">{{ __('Start Recurring') }}</label>
<div class="row">
<div class="col">
<input type="date" name="startRecur" id="input-startRecur" class="form-control form-control-alternative{{ $errors->has('startRecur') ? ' is-invalid' : '' }}" placeholder="{{ __('Start Recurring') }}" value="{{ old('startRecur') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Start date: {{ $old_event['startRecur'] }}</p>
</div>
</div>
#if ($errors->has('startRecur'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('startRecur') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('endRecur') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-endRecur">{{ __('End Recurring') }}</label>
<div class="row">
<div class="col">
<input type="date" name="endRecur" id="input-endRecur" class="form-control form-control-alternative{{ $errors->has('endRecur') ? ' is-invalid' : '' }}" placeholder="{{ __('End Recurring') }}" value="{{ old('endRecur') }}" autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current End date: {{ $old_event['endRecur'] }}</p>
</div>
</div>
#if ($errors->has('endRecur'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('endRecur') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('daysOfWeek') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-daysOfWeek">{{ __('Days of week') }}</label>
<div class="row">
<div class="col">
<select multiple size="7" name="daysOfWeek[]" id="input-daysOfWeek" class="form-control form-control-alternative{{ $errors->has('daysOfWeek') ? ' is-invalid' : '' }}" placeholder="{{ __('days Of Week') }}" autofocus>
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
</select>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current selected days: {{ $old_event['daysOfWeek'] }}</p>
</div>
</div>
#if ($errors->has('daysOfWeek'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('daysOfWeek') }}</strong>
</span>
#endif
</div>
</fieldset>
<div class="form-group{{ $errors->has('assignesto') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-assignesto">{{ __('assignes to') }}</label>
<div class="row">
<div class="col">
<select multiple size="3" name="assignesto[]" id="input-assignesto" class="form-control form-control-alternative{{ $errors->has('assignesto') ? ' is-invalid' : '' }}" placeholder="{{ __('assignesto') }}" required autofocus>
#foreach($assignees_array as $key)
<option value="{{ $key->id }}">{{ $key->name }}</option>
#endforeach
</select>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current assignees: {{ $old_event['assigned_to_string'] }}</p>
</div>
</div>
#if ($errors->has('assignesto'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('assignesto') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('location') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-location">{{ __('location') }}</label>
<div class="row">
<div class="col">
<input type="text" name="location" id="input-location" class="form-control form-control-alternative{{ $errors->has('location') ? ' is-invalid' : '' }}" placeholder="{{ __('location') }}" value="{{ $old_event['location'] }}" required autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Location: {{ $old_event['location'] }}</p>
</div>
</div>
#if ($errors->has('location'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('location') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('notes') ? ' has-danger' : '' }}">
<label class="form-control-label" for="input-notes">{{ __('notes') }}</label>
<div class="row">
<div class="col">
<input type="text" name="notes" id="input-notes" class="form-control form-control-alternative{{ $errors->has('notes') ? ' is-invalid' : '' }}" placeholder="{{ __('notes') }}" value="{{ $old_event['notes'] }}" required autofocus>
</div>
<div class="col">
<p style="font-size:14px;padding: 10px;">Current Notes: {{ $old_event['notes'] }}</p>
</div>
</div>
#if ($errors->has('notes'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('notes') }}</strong>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('notes') ? ' has-danger' : '' }}">
<p style="font-size:14px;padding: 10px;">Event created by: {{ $old_event['assigned_by_detail'] }}</p>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary mt-4">{{ __('Save') }}</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
</script>
#include('layouts.footers.auth')
</div>
#endsection
#push('js')
<script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.min.js"></script>
<script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.extension.js"></script>
#endpush
I had to make another blade and move edit functions to another controller.And this was because of free dashboard template I'm using.It has built in authentication functions but blocks some parts for free users.Anyway thanks for your help.
Related
how can i get the values of some inputs from database after select option in dropdown
I'm building an HTML form that contains all information about clients, and the others information, so I would when I choose the name of the client that is in the dropdown (select options that contain all name of clients ) the other input fields like (address, tel, email) should be filled automatically. I don't know what I have to use ajax or jquery and how to use it. this is my view: #extends('layouts.master') #section('content') <div class="container"> <div class="row"> <div class="col-md-11"> <div class="panel panel-default"> <div class="panel-heading">Création de commandes</div> <div class="panel-body"> <form id="form2" class="form-horizontal" method="POST" action="{{url('gestion_commandes/create')}}"> {{ csrf_field() }} <div class="form-group{{ $errors->has('nomp') ? ' has-error' : '' }}"> <label for="nomp" class="col-md-1 control-label">Client</label> <div class="col-md-5"> <select name="nomclient" id="nomclient" class="form-control dynamic" data-dependent="organisme" required autofocus> <option>--Select--</option> #foreach ($clientscombos as $clientcombos) <option value="{{$clientcombos->nom}}">{{$clientcombos->nom}} </option> #endforeach </select> </div> {{ csrf_field() }} <label for="organisme" class="col-md-1 control-label">Organisme</label> <div class="col-md-5"> <input id="organisme" type="text" class="form-control" name="organisme" value="{{$clientcombos->organisme}}" required autofocus> #if ($errors->has('organisme')) <span class="help-block"> <strong>{{ $errors->first('organisme') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('adresse') ? ' has-error' : '' }}"> <label for="adresse" class="col-md-1 control-label">Adresse</label> <div class="col-md-5"> <input id="adresse" type="text" class="form-control" name="adresse" value="{{$clientcombos->adresse}}" autofocus> #if ($errors->has('adresse')) <span class="help-block"> <strong>{{ $errors->first('adresse') }}</strong> </span> #endif </div> <label for="emailp" class="col-md-1 control-label">E-Mail Address</label> <div class="col-md-5"> <input id="emailp" type="email" class="form-control" name="emailp" placeholder="Saisir l'adresse email" required autofocus> #if ($errors->has('emailp')) <span class="help-block"> <strong>{{ $errors->first('emailp') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('adressep') ? ' has-error' : '' }}"> <label for="tel" class="col-md-1 control-label">Tel</label> <div class="col-md-3"> <input id="tel" type="Tel" class="form-control" name="tel" value="{{$clientcombos->tel1}}" required autofocus> #if ($errors->has('tel')) <span class="help-block"> <strong>{{ $errors->first('tel') }}</strong> </span> #endif </div> <label for="tel2p" class="col-md-1 control-label">Tel2</label> <div class="col-md-3"> <input id="tel2p" type="Tel" class="form-control" name="tel2p" value="+2126" required autofocus> #if ($errors->has('tel2p')) <span class="help-block"> <strong>{{ $errors->first('tel2p') }}</strong> </span> #endif </div> <label for="faxp" class="col-md-1 control-label">Fax</label> <div class="col-md-3"> <input id="faxp" type="Tel" class="form-control" name="faxp" value="{{$clientcombos->fax}}" required autofocus> #if ($errors->has('faxp')) <span class="help-block"> <strong>{{ $errors->first('faxp') }}</strong> </span> #endif </div> </div> <div class=" panel panel-success"> </div> <div class=" panel panel-success"> </div> <div class="form-group{{ $errors->has('daterecep') ? ' has-error' : '' }}"> <label for="commercial" class="col-md-1 control-label">Commercial</label> <div class="col-md-3"> <select name="commercial" id="commercial" class="form-control" required autofocus> <option>--Select--</option> #foreach ($combocommerciaux as $combocommercial) <option value="{{$combocommercial->name}}">{{$combocommercial->name}} </option> #endforeach </select> </div> <label for="datereception" class="col-md-1 control-label">Date de réception</label> <div class="col-md-3"> <input id="datereception" type="date" class="form-control" name="datereception" placeholder="Saisir le nom complet" required autofocus> #if ($errors->has('datereception')) <span class="help-block"> <strong>{{ $errors->first('datereception') }}</strong> </span> #endif </div> <label for="dateprelev" class="col-md-1 control-label">Date de prélevement</label> <div class="col-md-3"> <input id="dateprelev" type="date" class="form-control" name="dateprelev" placeholder="Saisir le nom complet" required autofocus> #if ($errors->has('dateprelev')) <span class="help-block"> <strong>{{ $errors->first('dateprelev') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('commercial') ? ' has-error' : '' }}"> <label for="savedby" class="col-md-9 control-label">Enregistrée par </label> <div class="col-md-3"> <input id="savedby" type="text" class="form-control" name="savedby" value="{{Auth::user()->name}}" required autofocus> #if ($errors->has('savedby')) <span class="help-block"> <strong>{{ $errors->first('savedby') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrrowsol') ? ' has-error' : '' }}"> <label for="nbrrowsow" class="col-md-1 control-label">Sol </label> <div class="col-md-3"> <input id="nbrrowsol" type="number" class="form-control" name="nbrrowsol" required autofocus> #if ($errors->has('nbrrowsol')) <span class="help-block"> <strong>{{ $errors->first('nbrrowsol') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrroweau') ? ' has-error' : '' }}"> <label for="nbrroweau" class="col-md-1 control-label">Eau </label> <div class="col-md-3"> <input id="nbrroweau" type="number" class="form-control" name="nbrroweau" required autofocus> #if ($errors->has('nbrroweau')) <span class="help-block"> <strong>{{ $errors->first('nbrroweau') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrrowveg') ? ' has-error' : '' }}"> <label for="nbrrowveg" class="col-md-1 control-label">VEG </label> <div class="col-md-3"> <input id="nbrrowveg" type="number" class="form-control" name="nbrrowveg" required autofocus> #if ($errors->has('nbrrowveg')) <span class="help-block"> <strong>{{ $errors->first('nbrrowveg') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrrowbiof') ? ' has-error' : '' }}"> <label for="nbrrowbiof" class="col-md-1 control-label">Fertilisant </label> <div class="col-md-3"> <input id="nbrrowbiof" type="number" class="form-control" name="nbrrowbiof" placeholder="Saisir l'adresse email" required autofocus> #if ($errors->has('nbrrowbiof')) <span class="help-block"> <strong>{{ $errors->first('nbrrowbiof') }}</strong> </span> #endif </div> <div class="col-md-6 control-label"> <button type="submit" class="btn btn-primary" onclick="location.href='{{url('gestion_regions/create')}}'" >Executer</button> </div> </div> <div class="form-group{{ $errors->has('nbrrowmicair') ? ' has-error' : '' }}"> <label for="nbrrowmicair" class="col-md-1 control-label">Mic Air </label> <div class="col-md-3"> <input id="nbrrowmicair" type="number" class="form-control" name="nbrrowmicair" required autofocus> #if ($errors->has('nbrrowmicair')) <span class="help-block"> <strong>{{ $errors->first('nbrrowmicair') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrrowmiceau') ? ' has-error' : '' }}"> <label for="nbrrowmiceau" class="col-md-1 control-label">Mic Eau</label> <div class="col-md-3"> <input id="nbrrowmiceau" type="number" class="form-control" name="nbrrowmiceau" required autofocus> #if ($errors->has('nbrrowmiceau')) <span class="help-block"> <strong>{{ $errors->first('nbrrowmiceau') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('nbrrowmicsurface') ? ' has-error' : '' }}"> <label for="nbrrowmicsurface" class="col-md-1 control-label">Mic Surface </label> <div class="col-md-3"> <input id="nbrrowmicsurface" type="number" class="form-control" name="nbrrowmicsurface" placeholder="Saisir l'adresse email" required autofocus> #if ($errors->has('nbrrowmicsurface')) <span class="help-block"> <strong>{{ $errors->first('nbrrowmicsurface') }}</strong> </span> #endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-success"> Enregistrer </button> </div> </div> </form> </div> </div> </div> </div> </div> #endsection this is controller: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; use App\Client; class DynamicDependent extends Controller { public function comboboxclients() { $clientscombos = DB::select('select * from clients'); $combocommerciaux = DB::select('select * from commercials'); return view('gestion_commandes.create',['clientscombos' => $clientscombos , 'combocommerciaux' => $combocommerciaux]); } }
You have to: 1) Server-side: create another action which will fetch client data based on value from select(I suggest you using an client id as select value inside your template). 2) Client-side: add hook on select value change('change' event inside JS), which will send an AJAX request(containing selected value) to action created on step 1, and populate form inputs with received data. That's pretty much it. Fell free to ask about specific implementation details, but keep in mind that no one will write code for you here, you have to do it yourself, but you'll be fine with this directions.
sending error message laravel required inputs
so i wanted to make validation to my register form so i made all my inputs required so i can test my validation that it works or not, so this is what i used in my controller $Message = [ 'required' => 'This input is required', ]; $validator = Validator::make($request->all(), [ 'name' => 'required', 'email' => 'required', 'password' => 'required', 'UserName' => 'required', 'Phone' => 'required', 'SSN' => 'required', 'SDT' => 'required', 'Country' => 'required', 'InsuranceAmount' => 'required', 'City' => 'required', 'Location' => 'required' ], $Message); if ($validator->fails()) { return redirect('/admin/users/create') ->withErrors($validator) ->withInput(); } $user = new User; $user->name = Input::get('name'); $user->email = Input::get('email'); $user->password = bcrypt(Input::get('password')); $user->UserName = input::get('UserName'); $user->Phone = input::get('Phone'); $user->SSN = input::get('SSN'); $user->SDT = input::get('SDT'); $user->Country = input::get('Country'); $user->City = input::get('City'); $user->Location = input::get('Location'); $user->save(); return Redirect::to('/admin/users')->with('message', 'User Created'); Now if theres no errors it works fine and redirect to user list, but if a input is empty it will just redirect to the creation page whict is what i wanted but the problem is it won't send the error message with the redirect i tried dd the validator and it has all the messages fine heres my view <form class="form-horizontal" role="form" method="POST" action="{{ Route('userstore') }}"> {!! csrf_field() !!} <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">الاسم</label> <div class="col-md-6"> <input type="text" class="form-control" name="name" value="{{ old('name') }}"> #if ($errors->has('name')) <span class="help-block"> <strong>{{ $errors->first('name') }}</strong> </span> #endif </div> </div> <div class="form-group {{$errors->has('UserName') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">اسم المستخدم</label> <div class="col-md-6"> <input type="text" class="form-control" name="UserName" value="{{ old('UserName') }}"> #if ($errors->has('UserName')) <span class="help-block"> <strong>{{ $errors->first('UserName') }}</strong> </span> #endif </div> </div> <div class="form-group {{$errors->has('Phone') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">رقم الجوال</label> <div class="col-md-6"> <input type="text" class="form-control" name="Phone" value="{{old('Phone')}}"> #if ($errors->has('Phone')) <span class="help-block"> <strong>{{ $errors->first('Phone') }}</strong> </span> #endif </div> </div> <div class="form-group {{$errors->has('SSN') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">الرقم الوطني</label> <div class="col-md-6"> <input type="text" class="form-control" name="SSN" value="{{old('SSN')}}"> #if ($errors->has('SSN')) <span class="help-block"> <strong>{{ $errors->first('SSN') }}</strong> </span> #endif </div> </div> <div class="form-group {{$errors->has('SDT') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">نوع الوثيقة</label> <div class="col-md-6"> <input type="text" class="form-control" name="SDT" value="{{old('SDT')}}"> #if ($errors->has('SDT')) <span class="help-block"> <strong>{{ $errors->first('SDT') }}</strong> </span> #endif </div> </div> <div class="form-group {{$errors->has('Country') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">الدولة</label> <div class="col-md-6"> <select class="form-control" name="Country"> <option>الاردن</option> </select> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">المدينة</label> <div class="col-md-6"> <select class="form-control" name="City" > <option>عمان</option> </select> </div> </div> <div class="form-group {{$errors->has('Location') ? 'has-error' : ''}}"> <label class="col-md-4 control-label">اسم الشارع</label> <div class="col-md-6"> <input type="text" class="form-control" name="Location" value="{{old('Location')}}"> #if ($errors->has('Location')) <span class="help-block"> <strong>{{ $errors->first('Location') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }} ltr-input"> <label class="col-md-4 control-label">البريد الإلكتروني</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> #if ($errors->has('email')) <span class="help-block"> <strong>{{ $errors->first('email') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }} ltr-input"> <label class="col-md-4 control-label">كلمة المرور</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> #if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }} ltr-input"> <label class="col-md-4 control-label">تأكيد كلمة المرور</label> <div class="col-md-6"> <input type="password" class="form-control" name="password_confirmation"> #if ($errors->has('password_confirmation')) <span class="help-block"> <strong>{{ $errors->first('password_confirmation') }}</strong> </span> #endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary pull-right"> <i class="fa fa-btn fa-user"></i> تسجيل </button> </div> </div> </form> and btw this is laravel 5.1
I fix the problem by upgrading my project from laravel 5.1 to 5.5
Laravel 5.3 Session store not set on request
I have a Laravel project and I'm getting the following error and tried other questions asked before but i can't understand the problem. plz anybody guide me. RuntimeException in C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Http\Request.php line 905: My routes.php file is here: Route::group(['middleware' => ['web']], function () { // default public route Route::get('/', 'DashboardController#index'); // Rediret for Login Page Route::get('/loginmsg', 'LoginMessageController#index'); // dashboard route Route::get('dashboard/index', 'DashboardController#index'); }); //Route::get('/service/get/login','App\Http\Controllers\Auth\LoginMessageController#index')->name('xyz'); Route::group(['middleware' => 'web'], function () { Route::auth(); Route::get('register', 'DashboardController#index'); }); Here's my register.blade.php #extends('layouts.app') #section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Register</div> <div class="panel-body"> <form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}"> {{ csrf_field() }} <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> <label for="name" class="col-md-4 control-label">Name</label> <div class="col-md-6"> <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}"> #if ($errors->has('name')) <span class="help-block"> <strong>{{ $errors->first('name') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <label for="email" class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}"> #if ($errors->has('email')) <span class="help-block"> <strong>{{ $errors->first('email') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <label for="password" class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input id="password" type="password" class="form-control" name="password"> #if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input id="password-confirm" type="password" class="form-control" name="password_confirmation"> #if ($errors->has('password_confirmation')) <span class="help-block"> <strong>{{ $errors->first('password_confirmation') }}</strong> </span> #endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> <i class="fa fa-btn fa-user"></i> Register </button> </div> </div> </form> </div> </div> </div> </div> </div> #endsection
Validation is not working on Registration & Login form
I've following this Blog for multi table authentication. I downloaded the project as it is and run the project. Everything works but validation is not working. Now message showing while I post an empty form. Here is the code: <form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}"> {{ csrf_field() }} <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Name</label> <div class="col-md-6"> <input type="text" class="form-control" name="name" value="{{ old('name') }}"> #if ($errors->has('name')) <span class="help-block"> <strong>{{ $errors->first('name') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> #if ($errors->has('email')) <span class="help-block"> <strong>{{ $errors->first('email') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> #if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password_confirmation"> #if ($errors->has('password_confirmation')) <span class="help-block"> <strong>{{ $errors->first('password_confirmation') }}</strong> </span> #endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> <i class="fa fa-btn fa-user"></i>Register </button> </div> </div> </form> According to the code error should be shown. I don't understand why its not working.
There is no validation rules or incorrect validation rules in your post controller.
Laravel 5.2: How to add a register page?
I am using Laravel 5.2, and I use php artisan make:auth to make register page and login page. Now, I would want to make two separated register pages,which used by two roles,seller and buyer , the two register pages named seller-register.blade.php and buyer-register.blade.php, in view,add a item named userType,respectively corresponding seller and buyer,like this: seller-register.blade.php <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Register</div> <div class="panel-body"> <form class="form-horizontal" role="form" method="POST" action="{{ url('/seller-register') }}"> {!! csrf_field() !!} <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Name</label> <div class="col-md-6"> <input type="text" class="form-control" name="name" value="{{ old('name') }}"> #if ($errors->has('name')) <span class="help-block"> <strong>{{ $errors->first('name') }}</strong> </span> #endif </div> </div> <div class="form-group"> <label class="col-md-4 form-control-label">User Type</label> <div class="col-md-6"> <label class="c-input c-radio"> <input id="userType" name="userType" type="radio" value="1" checked> <span class="c-indicator"></span> seller </label> </div> </div> <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> #if ($errors->has('email')) <span class="help-block"> <strong>{{ $errors->first('email') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> #if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> #endif </div> </div> <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> <label class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password_confirmation"> #if ($errors->has('password_confirmation')) <span class="help-block"> <strong>{{ $errors->first('password_confirmation') }}</strong> </span> #endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> <i class="fa fa-btn fa-user"></i>Register </button> </div> </div> </form> </div> </div> </div> </div> </div> Question: How to modify controller and other something?