Validating forms on laravel - laravel

Hi i getting this error When I try to validate a form, with this
$this->validate($request, [
'documento' => 'required|unique:cliente|max:55',
]);
htmlentities() expects parameter 1 to be string, array given (View: C:\sisVentas\resources\views\ventas\cliente\create.blade.php)
this is my view please help.
#extends ('layouts.admin')
#section ('contenido')
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<h3>Nuevo Cliente</h3>
#if (count($errors)>0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
</div>
{!!Form::open(array('url'=>'ventas/cliente','method'=>'POST','autocomplete'=>'off', 'files'=>'true'))!!}
{{Form::token()}}
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="empresa">Empresa</label>
<input type="text" name="empresa" value="{{old('empresa')}}" class="form-control"
placeholder="Empresa...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="contacto">Direccion</label>
<input type="text" name="direccion" value="{{old('direccion')}}" class="form-control"
placeholder="Direccion...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label>Tipo Documento</label>
<select name="tipo_documento" class="form-control">
<option value="J">J</option>
<option value="G">G</option>
<option value="V">V</option>
<option value="E">E</option>
</select>
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="Numero de documento">Numero de Documento</label>
<input type="text" name="documento" id="documento" required value="{{old('documento')}}"
onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control"
placeholder="Numero de Documento...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="razon_social">Razon Social</label>
<input type="text" name="razon_social" value="{{old('razon_social')}}" class="form-control"
placeholder="Razon social...">
</div>
</div>
</div>
<div class="row">
<div class="panel panel-primary">
<div class="panel-body">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" name="pnombre" id="pnombre" class="form-control" placeholder="Nombre...">
</div>
</div>
<div class="col-lg-5 col-sm-5 col-md-5 col-xs-12">
<div class="form-group">
<label for="telefonos">Telefonos</label>
<input type="text" name="ptelefono" id="ptelefono" class="form-control"
value="{{old('precio')}}" placeholder="Telefonos...">
</div>
</div>
<div class="col-lg-3 col-sm-3 col-md-3 col-xs-12">
<div class="form-group">
<label for="correo">Correo</label>
<input type="text" name="pcorreo" id="pcorreo" class="form-control"
value="{{old('correo')}}" placeholder="correo...">
</div>
</div>
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
<div class="form-group">
<button type="button" id="bt_add" class="btn btn-primary">Agregar</button>
</div>
</div>
<div class="col-lg-8 col-sm-8 col-md-8 col-xs-12">
<table id="detalles" class="table table-striped table-bordered table-condensed">
<thead style="background-color: #ccc">
<th>Opciones</th>
<th>Nombre</th>
<th>Contacto</th>
<th>Correo</th>
</thead>
<tfoot>
<th></th>
<th></th>
<th></th>
<th></th>
</tfoot>
<tbody>
</tbody>
</table>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<button class="btn btn-primary" id="guardar" type="submit">Guardar</button>
<button class="btn btn-danger" type="reset">Cancelar</button>
</div>
</div>
</div>
{!!Form::close() !!}
#push ('scripts') <!-- Trabajar con el script definido en el layout-->
<script>
//////////
$('#guardar').hide();
$(document).ready(function () {
$('#bt_add').click(function () {
agregar();
});
});
var cont = 0;
var total = 0;
subtotal = [];
function agregar() {
nombre = $('#pnombre').val();
telefono = $('#ptelefono').val();
correo = $('#pcorreo').val();
if (nombre != "" && telefono != "") {
total = total + subtotal[cont];
var fila = '<tr class="selected" id="fila' + cont + '"><td><button type="button" class="btn btn-warning" onclick="eliminar(' + cont + ')" >X</button></td><td><input type="text" name="nombre[]" value="' + nombre + '"</td><td><input type="text" name="telefono[]" value="' + telefono + '"</td><td><input type="text" name="correo[]" value="' + correo + '"</td></tr>';
cont++;
limpiar();
$('#detalles').append(fila);
$('#guardar').show();
} else {
alert("Error al ingresar los detalles del contacto, revise los datos del contacto ");
}
}
function limpiar() {
$('#pnombre').val("");
$('#ptelefono').val("");
$('#pcorreo').val("");
}
function eliminar(index) {
$("#fila" + index).remove();
evaluar();
}
</script>
#endpush
#endsection
and this is my controller
<?php
namespace sisVentas\Http\Controllers;
use Illuminate\Http\Request;
use sisVentas\Http\Requests;
use sisVentas\Persona;
use sisVentas\Contacto;
use Response;
use sisVentas\Evento;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use sisVentas\Http\Requests\PersonaFormRequest;
use DB;
class ClienteController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
if ($request)
{
$query=trim($request->get('searchText'));
$clientes=DB::table('cliente')
->where ('empresa','LIKE','%'.$query.'%')
->orwhere ('tipo_documento','LIKE','%'.$query.'%')
->orwhere ('documento','LIKE','%'.$query.'%')
->orwhere ('direccion','LIKE','%'.$query.'%')
->orwhere ('razon_social','LIKE','%'.$query.'%')
->orderBy('codigo_cliente','desc')
->paginate(7);
return view('ventas.cliente.index',["clientes"=>$clientes,"searchText"=>$query]);
}
}
public function create()
{
return view("ventas.cliente.create");
}
public function store (Request $request)
{
$this->validate($request, [
'documento' => 'required|unique:cliente|max:55',
]);
try {
DB::beginTransaction();
$persona=new Persona;
$persona->tipo_documento=$request->get('tipo_documento');
$persona->documento=$request->get('documento');
$persona->empresa=$request->get('empresa');
$persona->direccion=$request->get('direccion');
$persona->razon_social=$request->get('razon_social');
$persona->save();
$id = $persona->codigo_cliente;
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Nuevo Ingreso';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
$nombre=$request->get('nombre');
$telefono = $request->get('telefono');
$correo = $request->get('correo');
$cont = 0;
while ($cont < count($nombre)) {
# code...
$detalle = new Contacto();
$detalle->idempresa=$id;
$detalle->nombre=$nombre[$cont];
$detalle->telefono=$telefono[$cont];
$detalle->correo=$correo[$cont];
$detalle->save();
$cont=$cont+1;
}
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}
return Redirect::to('ventas/cliente/create');
}
public function show($id)
{
return view("ventas.cliente.show",["persona"=>Persona::findOrFail($id)]);
}
public function edit($id)
{
return view("ventas.cliente.edit",["persona"=>Persona::findOrFail($id)]);
}
public function update(PersonaFormRequest $request,$id)
{
$persona=Persona::findOrFail($id);
$persona->tipo_documento=$request->get('tipo_documento');
$persona->documento=$request->get('documento');
$persona->empresa=$request->get('empresa');
$persona->direccion=$request->get('direccion');
$persona->razon_social=$request->get('razon_social');
$persona->update();
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Modificacion';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
return Redirect::to('ventas/cliente');
}
public function destroy($id)
{
$persona=Persona::findOrFail($id);
$clientes = DB::table('cliente')->where('codigo_cliente', '=', $id)->delete();
$persona->update();
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Eliminar';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
return Redirect::to('ventas/cliente');
}
}

this issue appear because one of the value that is between the {{}} returning an array instead of string.
and i think it is in the following code
<input type="text" name="pcorreo" id="pcorreo" class="form-control" value="{{old('correo')}}" placeholder="correo...">
and as I saw in your view code you have an input with name correo[] that is an array, and after the validation failure the controller redirect to the form view, the old('correo') function return an array instead of string

Related

My data is not saving in the database.I could not do it in the controller part, how can I do something

When you save, other input data comes to the database, while the data from TourDay does not come. The relationship is established in the Migration and Model section. I could not do it in the controller part, how can I do something..
my blade:
<div class="row">
<div class="col-lg-12">
<div class="card card-custom card-stretch ">
<div class="card-header">
<h3 class="card-title">GRUP OLUŞTUR</h3>
</div>
<form method="post" class="form" id="dynamic_form" enctype="multipart/form-data">
#csrf
<div class="card-body">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li><b>{{ $error }}</b></li>
#endforeach
</ul>
</div>
#endif
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right"><strong>Otel Seçimi:</strong></label>
<div class="col-lg-3">
<select class="form-control select2 " id="kt_select2_5" name="hotel[]" multiple="" tabindex="-1" aria-hidden="true">
<optgroup label="Oteller">
#foreach($hotels as $hotel)
<option value="{{$hotel->id}}" >{{$hotel->name}}</option>
#endforeach
</optgroup>
</select>
</div>
<label class="col-lg-2 col-form-label text-lg-right"><strong>Grup Kodu :</strong></label>
<div class="col-lg-3">
<div class="input-group input-group">
<div class="input-group-prepend"><span class="input-group-text" >Grup-Kodu:</span></div>
<input type="text" class="form-control form-control-solid" placeholder="TourKey-123-456" name="code" value="{{old('code')}}">
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right"><strong>Rehber Ata:</strong></label>
<div class="col-lg-3">
<select class="form-control form-control-solid" id="exampleSelectd" name="guide_id">
#foreach($guides as $guide)
<option value="{{ $guide->id }}" #if(old('guide_id')===$guide->id) selected #endif>{{$guide->full_name}}</option>
#endforeach
</select>
</div>
<label class="col-lg-2 col-form-label text-lg-right"><strong>Müşteri Seçimi:</strong></label>
<div class="col-lg-3">
<select class="form-control select2 " id="kt_select2_3" name="user[]" multiple="" data-select2-id="kt_select2_3" tabindex="-1" aria-hidden="true">
<optgroup label="Müşteriler" >
#foreach($users as $user)
<option value="{{$user->id}}">{{$user->full_name}}</option>
#endforeach
</optgroup>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right"><strong>Başlangıç Tarihi:</strong></label>
<div class="col-lg-3">
<div class="input-group date">
<input type="text" class="form-control" id="kt_datepicker_2" name="started_at" value="{{old('started_at')}}" placeholder="Başlangıç Tarihi seçin.">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-calendar-check-o"></i>
</span>
</div>
</div>
</div>
<label class="col-lg-2 col-form-label text-lg-right"><strong>Bitiş Tarihi:</strong></label>
<div class="col-lg-3">
<div class="input-group date">
<input type="text" class="form-control" id="kt_datepicker_2" name="finished_at" value="{{old('finished_at')}}" placeholder="Başlangıç Tarihi seçin.">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-calendar-check-o"></i>
</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label text-lg-right"><strong>Aktivite olacak mı? (Opsiyonel)</strong></label>
<div class="col-lg-3 d-flex justify-content-center">
<div class="radio-inline">
<label class="radio radio-lg">
<input type="radio" onclick="aktivite(0)" #if(old('activity')) checked="checked" #endif name="radios3_1" class="form-control"/>
<span></span>
Evet
</label>
<label class="radio radio-lg">
<input type="radio" onclick="aktivite(1)" #if(!old('activity')) style='display:none' #endif name="radios3_1" class="form-control"/>
<span></span>
Hayır
</label>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right" for="kt_select2_2"></label>
<div class="col-lg-4">
<div class="form-group" id="myAktivite">
<label for="kt_select2_2"><strong>Aktivite Seçimi Yapın:</strong></label>
<select class="form-control select2 " id="kt_select2_2" name="activity[]" multiple="" data-select2-id="kt_select2_2" tabindex="-1" aria-hidden="true">
<optgroup label="Aktiviteler">
#foreach($activities as $activity)
<option value="{{$activity->id}}">{{$activity->title}}</option>
#endforeach
</optgroup>
</select>
</div>
</div>
</div>
</div>
<div class="separator separator-dashed my-8"></div>
<div class="row col-lg-6">
<div class="col-lg-1"></div>
<h4 class="title col-lg-4">TUR EKLE</h4>
</div>
<div class="separator separator-dashed my-8"></div>
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right"><strong>Tur Başlığı:</strong></label>
<div class="col-lg-3">
<input type="text" name="tour_title" value="{{old('tour_title')}}" class="form-control form-control-solid" placeholder="Lütfen tur başlığı giriniz"/>
</div>
<label class="col-lg-2 col-form-label text-lg-right"></label>
<div class="col-lg-3">
<div class="custom-file form-group">
<input type="file" class="custom-file-input form-control-solid" id="customFile" multiple>
<label class="custom-file-label" for="customFile">Resim Yükle</label>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label text-lg-right" for="editable"><strong>İçerik Detay</strong></label>
<div class="col-lg-8">
<textarea id="editable" class="form-control" placeholder="" name="tour_description" value="{{old('tour_description')}}">
</textarea>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-md-8">
<h3 align="center">Tur Detayı (Gün gün yapılacakları ekleyin):</h3>
<br />
<div class="table-responsive">
<span id="result"></span>
<table class="table table-bordered table-striped" id="user_table">
<thead>
<tr>
<th width="22%">Başlık(Kaçıncı Gün)</th>
<th width="22%">İçerik</th>
<th width="22%">Öğle Yemeği</th>
<th width="22%">Akşam Yemeği</th>
<th width="12%">Action</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<div class="card-footer">
<div class="row ">
<div class="col-lg-10 d-flex justify-content-end">
<button type="submit" name="save" id="save" class="btn btn-success mr-2">Kaydet</button>
<button type="reset" class="btn btn-secondary">İptal Et</button>
</div>
<div class="col-lg-2"></div>
</div>
</div>
</form>
</div>
</div>
my script:
<script>
$(document).ready(function(){
var count = 1;
dynamic_field(count);
function dynamic_field(number)
{
html = '<tr>';
html += '<td><input type="text" name="title[]" class="form-control" /></td>';
html += '<td><input type="text" name="description[]" class="form-control" /></td>';
html += '<td><input type="text" name="lunch[]" class="form-control" /></td>';
html += '<td><input type="text" name="dinner[]" class="form-control" /></td>';
if(number > 1)
{
html += '<td><button type="button" name="remove" id="" class="btn btn-light-danger remove"><i class="la la-trash-o">Sil</button></td></tr>';
$('tbody').append(html);
}
else
{
html += '<td><button type="button" name="add" id="add" class="btn btn-light-success"><i class="la la-plus"> Ekle' +
'' +
'</button></td></tr>';
$('tbody').html(html);
}
}
$(document).on('click', '#add', function(){
count++;
dynamic_field(count);
});
$(document).on('click', '.remove', function(){
count--;
$(this).closest("tr").remove();
});
$('#dynamic_form').on('submit', function(event){
event.preventDefault();
$.ajax({
url:'{{ route("groups.store") }}',
method:'post',
data:$(this).serialize(),
dataType:'json',
beforeSend:function(){
$('#save').attr('disabled','disabled');
},
success:function(data)
{
if(data.error)
{
var error_html = '';
for(var count = 0; count < data.error.length; count++)
{
error_html += '<p>'+data.error[count]+'</p>';
}
$('#result').html('<div class="alert alert-danger">'+error_html+'</div>');
}
else
{
dynamic_field(1);
$('#result').html('<div class="alert alert-success">'+data.success+'</div>');
}
$('#save').attr('disabled', false);
}
})
});
});
</script>
my Group Model:
protected $fillable = [
'guide_id','code','started_at','finished_at','tour_title','tour_description'
];
public function tourDays(){
return $this ->hasMany('App\Models\TourDay');
}
my TourDay Model:
protected $fillable = [
'group_id','title', 'description','lunch','dinner'
];
public function group(){
return $this ->belongsTo('App\Models\Group');
}
my GroupController:
public function store(Request $request)
{
$data=$request->only('guide_id','code','started_at','finished_at','tour_title','tour_description');
$group=Group::create($data);
if($request->ajax())
{
$rules = array(
'title.*' => 'required',
'description.*' => 'required',
'lunch.*'=>'required',
'dinner.*'=>'required',
);
$error =Validator::make($request->all(), $rules);
if($error->fails())
{
return response()->json([
'error' => $error->errors()->all()
]);
}
$title = $request->title;
$description = $request->description;
$lunch = $request->lunch;
$dinner = $request->dinner;
for($count = 0; $count < count($title); $count++)
{
$tourDay = new TourDay([
'title' => $title[$count],
'description' => $description[$count],
'lunch' => $lunch[$count],
'dinner' => $dinner[$count]]);
$group->tourDays()->saveMany($tourDay);
$data = array(
'title' => $title[$count],
'description' => $description[$count],
'lunch' => $lunch[$count],
'dinner' => $dinner[$count]
);
$insert_data[] = $data;
}
TourDay::insert($insert_data);
}
return redirect()
->route('groups.index')->withMessage('Rehber başarıyla oluşturuldu!');
}
In your store method put this codes:
public function store(Request $request) {
$data=$request->only('guide_id', 'code', 'started_at', 'finished_at','tour_title', 'tour_description');
$group=Group::create($data);
if($request->ajax())
{
$rules = array(
'title.*' => 'required',
'description.*' => 'required',
'lunch.*'=>'required',
'dinner.*'=>'required',
);
$error =Validator::make($request->all(), $rules);
if($error->fails())
{
return response()->json([
'error' => $error->errors()->all()
]);
}
$title = $request->title;
$description = $request->description;
$lunch = $request->lunch;
$dinner = $request->dinner;
for($count = 0; $count < count($title); $count++)
{
$tourDay = [
'title' => $title[$count],
'description' => $description[$count],
'lunch' => $lunch[$count],
'dinner' => $dinner[$count],
'group_id' => $group->id
];
TourDay::create($tourDay);
}
}
return redirect()
->route('groups.index')->withMessage('Rehber başarıyla oluşturuldu!');
}

How to insert this array of mySbjects in a database?

I've been trying to insert this into the database and I don't have any idea how to store this information into the database... The relationship between user and grade is many-to-many and between grade and mySubject is One-to-many.
<div class="row">
#foreach($grades as $grade)
<div class="card shadow mx-2 my-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold">
<div class="custom-control custom-checkbox">
<input class="custom-control-input #error('grade') is-invalid #enderror" type="checkbox" id="{{$grade->id}}" name="grade[]" value="{{ $grade->id }}"/>
<label class="custom-control-label pt-1" for="{{$grade->id}}">{{$grade->name}}</label>
</div>
</h6>
</div>
<div class="card-body">
#foreach($grade->subjects as $subject)
<div class="custom-control custom-checkbox mb-2">
<input class="custom-control-input" type="checkbox" id="{{$grade->id}}{{$subject->id}}" name="mySubjects[{{$grade->id}}][]" value="{{ $subject->name }}"/>
<label class="custom-control-label" for="{{$grade->id}}{{$subject->id}}">
{{$subject->name}}
</label>
</div>
#endforeach
</div>
</div>
#endforeach
</div>
The store function
public function store(Request $request)
{
$user->grades()->sync($request->grade);
if($request->mySubjects){
//. . . .
}
}
}
Try below code:
public function store(Request $request)
{
$user->grades()->sync($request->grade);
if($request->mySubjects){
$mySubjects = $request-> mySubjects;
$data = [];
foreach($mySubjects as $subject){
array_push($data,
'your database field name'=> $subject,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
}
YourModelName::insert($data);
}
}
}

how to make ajax call inside a edit form view in laravel

i have created a form for editing the record from db there is different time slots and i want to make delete function for them so i made a ajax call but am confused in URL www.hostname.com/dental/public/admin/manageschedule/1/api/ajax 404 (Not Found)
how to call ajax inside a laravel edit form
here is what i have done:
#extends('admin.layouts.app_inner')
#section('htmlheader_title')
Home
#endsection
#section('content')
#if (count($errors))
#foreach($errors->all() as $error)
<div class="alert alert-danger"><i class="fa fa-fw fa-close"></i> {{ $error }}</div>
#endforeach
#endif
#if ($message = Session::get('success'))
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i>Success</h4>
{{ $message }}
</div>
#endif
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title text-green"><b>Add Schedule</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<div class="box-body">
{!! Form::model($doctors, ['method' => 'PATCH','route' => ['manageschedule.update', $doctors->doctor_id],'class' => 'form-horizontal','files'=>true]) !!}
<div class="form-group">
<label class="col-md-3 control-label"> Select Doctor :</label>
<div class="col-md-5">
<select class="form-control" required name="doctor_name">
<?php $results = DB::select(DB::raw("SELECT day FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' Order BY id DESC ")); ?>
<option value="{{$doctors->doctor_name}}" SELECTED="YES">{{$doctors->doctor_name}}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" required> Day :</label>
<div class="col-md-5">
<div class="md-checkbox-inline">
<?php $day = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); ?>
#foreach($day as $days)
<input name="day[]" value="<?php echo $days; ?>" type="checkbox" class="md-checkbox" <?php
foreach ($results as $row) {
if ($row->day == $days) {
echo 'checked="checked"';
} else {
}
}
?> >
<label for="checkbox7"> <?php echo $days; ?> </label>
#endforeach
</div>
</div>
</div>
<?php foreach ($results as $row) { $d=$row->day;}
$result= DB::select(DB::raw("SELECT * FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' And day='".$d."' "));
?>
<div class="form-group">
<label class="col-md-3 control-label" required>Time slots</label>
<div class="col-md-6">
<table class="table table-bordered" id="employee_table" width="50%" >
<th>Start Time</th>
<th>End Time</th>
<th>Manage</th>
<?php foreach ($result as $key=>$vari) {
$id = $vari->id;
?>
<tr id="row1">
<td><div class="input-group ">
<input type="text" class="form-control" id="time" placeholder="Start Time" name="s_time[]" value="<?php echo $vari->start_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<td><div class="input-group ">
<input type="text" class="form-control" id="time1" placeholder="Start Time" name="e_time[]" value="<?php echo $vari->end_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<?php if ($key == 0) { ?>
<td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' disabled></td>
<?php } else { ?>
<td><span class='delete' id='del_<?php echo $id; ?>'><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' id='del_<?php echo $id; ?>' ></td>
</tr>
<?php }
}
?>
</table>
<a type="button" onclick="add_rows();" class="fa fa-plus-circle btn btn-primary"> Add More Time Slots</a>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"> Per Patient Time :</label>
<div class="col-md-5">
<div class=" input-daterange">
<input type="text" name="p_time" class="form-control" placeholder="Set per patient time" id="time1" value="<?php
echo $result[0]->p_time; ?>">
<span class="help-block"> You can set only minute </span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Visibility :</label>
<div class="col-md-5">
<input type="radio" id="checkbox2_5" value="Yes" name="visible" class="md-radiobtn" <?php
foreach($result as $check)
{
if($check->visibility=='Yes'){ echo 'checked="checked"';}else{}
} ?> >
<label for="checkbox2_5"> Yes </label>
<input type="radio" id="checkbox2_10" value="No" name="visible" class="md-radiobtn" <?php foreach($result as $check)
{
if($check->visibility=='No'){ echo 'checked="checked"';}else{}
} ?>>
<label for="checkbox2_10"> No </label>
</div>
</div>
<br><br>
<div class="box-footer">
<button type="submit" class="btn btn-info pull-right"id="submit">Update Schedule </button>
</div>
{!! Form::close() !!}
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time').timepicker();
})
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time1').timepicker();
})
});
</script>
<script type="text/javascript">
function add_rows()
{
$rowno = $("#employee_table tr").length;
$rowno = $rowno + 1;
$("#employee_table tr:last").after("<tr id='row" + $rowno + "'><td><div class='input-group '><input type='text' class='form-control' placeholder='Start Time' name='s_time[]' onclick=showtime('row" + $rowno + "')><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><div class='input-group '><input type='text' class='form-control' id='time1' placeholder='End Time' name='e_time[]'><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' onclick=delete_row('row" + $rowno + "')></td></tr>");
}
function delete_row(rowno)
{
$('#' + rowno).remove();
}
</script>
<script type="text/javascript">
//Variant Deleting script///
$(document).ready(function () {
// Delete
$('.delete').click(function () {
var el = this;
var id = this.id;
var splitid = id.split("_");
// Delete id
var deleteid = splitid[1];
alert('Are you sure you want to delete?');
$.ajax({
url: 'api/ajax',
type: 'delete',
data: {id: deleteid},
success: function (response) {
// Removing row from HTML Table
$(el).closest('tr').css('background', 'tomato');
$(el).closest('tr').fadeOut(800, function () {
$(this).remove();
});
}
});
});
});
</script>
<meta name="_token" content="{!! csrf_token() !!}" />
#endsection
here is my controller of api
Route::post('ajax','Controller#ajax')->name('ajax');
here is my web route:
Route::get('/', function () {
return view('auth.login');
});
Route::post('/', function () {
return view('auth.login')->with('successMsg','Please Select A role .');
});
Route::prefix('admin')->group(function() {
Route::get('/login', 'Auth\AdminLoginController#showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\AdminLoginController#login')->name('admin.login.submit');
Route::get('/', 'AdminController#index')->name('admin.home');
Route::resource('managedoctor', 'AddDocController');
Route::resource('managefront', 'AddFrontController');
Route::resource('managepatient', 'AddPatientController');
Route::resource('manageschedule', 'AddScheduleController');
Route::get('/logout', 'Auth\AdminLoginController#logout')->name('admin.logout');
});
Route::prefix('doctor')->group(function() {
Route::get('/login', 'Auth\DoctorLoginController#showLoginForm')->name('doctor.login');
Route::post('/login', 'Auth\DoctorLoginController#login')->name('doctor.login.submit');
Route::get('/', 'DoctorController#index')->name('doctor.home');
Route::get('/logout', 'Auth\DoctorLoginController#logout')->name('doctor.logout');
});
Route::prefix('frontdesk')->group(function() {
Route::get('/login', 'Auth\FrontdeskLoginController#showLoginForm')->name('frontdesk.login');
Route::post('/login', 'Auth\FrontdeskLoginController#login')->name('frontdesk.login.submit');
Route::get('/', 'FrontdeskController#index')->name('frontdesk.home');
Route::get('/logout', 'Auth\FrontdeskLoginController#logout')->name('frontdesk.logout');
});
my issue is resolved now the mistake i have done is i was not using the same route group in which am calling the controller with AUTH method

Last input added to a form in Laravel not inserting to database

I bought a ready made Laravel Tailor application, I am trying to add an additional input to it but after doing so, I tried to submit it to the database but the last one I added wasn't inserting. The input is in array.
All other values are inserting except for service_description[] which is newly added to the form.
What exactly could I be doing wrong?
Database Structure
HTML Codes:
#extends('admin.layouts.master')
#section('content')
<style type="text/css">
</style>
#if(Session::has('success'))
<div class="alert alert-success" role= "alert">
<strong>Successful:</strong>
{!! session('success') !!}
</div>
#endif
#if (count($errors) > 0)
<div class="row">
<div class="col-md-06">
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</div>
</div>
</div>
#endif
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption">
<i class="icon-equalizer font-red-sunglo"></i>
<span class="caption-subject font-red-sunglo bold uppercase">Order Submission</span>
<span class="caption-helper">Service Details</span>
</div>
<div class="tools">
</div>
</div>
<div class="portlet-body form">
<!-- BEGIN FORM-->
<form action="{{url('admin/save-order')}}" class="form-horizontal" method="POST">
<input name="order_create_by" type="hidden" value="{{ Auth::user()->id }}">
<div class="form-body">
{{ csrf_field() }}
<h3 class="form-section">Customer Info</h3>
<!--Start Customer Area-->
<div class="row">
<div class="col-md-6">
<!-- text input -->
<div class="form-group">
<label class="control-label col-md-4">Customer Name:</label>
<div class="col-md-8">
<input type="text" class="form-control" placeholder="Enter ..." name="service_cus_name" id="service_cus_name">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Email Address:</label>
<div class="col-md-8">
<input type="email" class="form-control" placeholder="Enter ..." name="service_cus_email" id="service_cus_email">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Order Create Date:</label>
<div class="col-md-8">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right createdpicker" name="service_crete_date" id="service_crete_date">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-4">Cell Number:</label>
<div class="col-md-8">
<input type="text" class="form-control" placeholder="Enter ..." name="cell_number" id="cell_number">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Order Delivery Date:</label>
<div class="col-md-8">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right dpicker" name="service_delivery_date" id="service_delivery_date">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label col-md-2">Cutomer Address:</label>
<div class="col-md-10">
<textarea class="form-control" rows="3" placeholder="Enter ..." name="service_cus_address" id="service_cus_address"></textarea>
</div>
</div>
</div>
</div>
<!--End Customer Area-->
<!--Start Service Order Area-->
<div class="form-section">
<h3 class="inlineBlock">Service Details with Measurement</h3>
<button type="button" class="btn dark flot-right " id="addService" disabled="disabled"> Add Another Service </button>
</div>
<div class="row">
<div class="col-md-3">
<div class="col-md-11">
<label>Select Service</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-10">
<label>Rate:</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-10">
<label>Quantity:</label>
</div>
</div>
<div class="col-md-2">
<div class="col-md-10">
<label>Amount:</label>
</div>
</div>
<div class="col-md-3">
<div class="col-md-10">
<label>Action</label>
</div>
</div>
</div>
<div class="row serviceRow redBorder" id="orderBox">
<div class="col-md-3">
<div class="form-group">
<div class="col-md-11">
<select class="form-control service_id" name="service_id[]" id="service_id">
<option selected="selected" disabled="disabled" value="0">Select Service</option>
#foreach($services as $service)
<option value="{{$service->id}}">{{$service->service_name}}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="col-md-10">
<input type="text" class="form-control service_price" placeholder="Rate" name="service_price[]" id="service_price" readonly>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="col-md-10">
<input type="text" class="form-control service_qty" placeholder="Quantity" id="service_qty" name="service_quantity[]">
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="col-md-10">
<input type="text" class="form-control amount" placeholder="Total" id="amount" name="service_amount[]" readonly>
</div> </div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="col-md-10">
<button type="button" class="btn removeService red btn-block" id="removeService" disabled="disabled"> Delete</button>
</div>
</div>
</div>
<div class="row pading-margin-zero">
<div class="col-md-12 col-md-offset-1">
<div class="form-group">
<div class="col-md-5" >
<textarea type="text" class="form-control service_measer" placeholder="Enter Measurement of Service ..." name="service_measer[]"></textarea>
</div>
<div class="col-md-5" >
<textarea type="text" class="form-control description service_description" placeholder="Description(s)" name="service_description[]" id="description"></textarea>
</div>
</div>
</div>
</div>
</div>
<!--End Service Order Area-->
</div>
<!--Start Form Footer Area-->
<div class="form-action">
<div class="row">
<div class="col-md-3">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-success">Total Amount</button>
</div>
<!-- /btn-group -->
<input type="text" class="form-control" id="total" name="total_amount" style="font-size:25px; font-weight: bold">
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-info">Discount Amount</button>
</div>
<!-- /btn-group -->
<input type="text" class="form-control" id="discount" name="discount_amount" style="font-size:25px; font-weight: bold">
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-warning">Advance Amount</button>
</div>
<!-- /btn-group -->
<input type="text" class="form-control" id="advance_amount" name="advance_amount" style="font-size:25px; font-weight: bold">
</div>
</div>
<div class="col-md-3">
<button type="submit" class="btn purple btn-block">Submit Order</button>
</div>
</div>
</div>
<!--End Form Footer Area-->
</form>
</div>
<script>
jQuery(document).ready(function() {
//Commom Script
$('.dpicker').datepicker({
autoclose: true
})
var currentDate = new Date();
$(".createdpicker").datepicker("setDate",currentDate);
$("#loader").css("display",'none');
$("#myDiv").removeAttr("style");
$("#addService").removeAttr("disabled");
//Start Order Form
$('form').submit(function() {
if ($.trim($("#service_cus_name").val()) === "") {
alert('Customer Name Field Empty');
return false;
}else if( $.trim($("#service_cus_email").val()) === ""){
alert('Email Address Field Empty');
return false;
}else if( $.trim($("#cell_number").val()) === ""){
alert('Cell Number Field Empty');
return false;
}else if( $.trim($("#service_crete_date").val()) === ""){
alert('Create Date Field Empty');
return false;
}else if( $.trim($("#service_delivery_date").val()) === ""){
alert('Delivery Date Field Empty');
return false;
}else if( $.trim($("#service_cus_address").val()) === ""){
alert('Customer Address Field Empty');
return false;
}
var flag = 0;
$(".service_qty").each(function(i){
if ($(this).val() == "")
flag++;
});
if(flag==0){
flagNew=0
$(".service_measer").each(function(i){
if ($(this).val() == "")
flagNew++;
});
if(flagNew==0){
return true;
}else{
alert("All Measurement Fileds Requried");
return false;
}
}else{
alert("All Service Quantity Fileds Requried");
return false;
}
});
$("#addService").click(function(){
//
//alert('addButton');
var serviceRowQty = $('.serviceRow').length;
//alert(serviceRowQty);
$("#orderBox:last").clone(true).insertAfter("div.serviceRow:last");
$("div.serviceRow:last input").val('');
$("div.serviceRow:last textarea").val('');
$("div.serviceRow:last select").prop('selectedIndex',0);
$("div.serviceRow:last label").text('');
$("div.serviceRow .removeService").prop('disabled', false);
return false;
})
$(document).on("click" , "#removeService" , function() {
//alert('deletebutton');
var serviceRowQty = $('.serviceRow').length;
if (serviceRowQty == 1){
$("div.serviceRow .removeService").prop('disabled', true);
return false;
$(".serviceRow").css("display", "block");
}else{
$(this).closest('.serviceRow').remove();
if(serviceRowQty==1){
//return false;
$("div.serviceRow .removeService").prop('disabled', true);
return false
}else{
$("div.serviceRow .removeService").prop('disabled', false);
}
//$(".serviceRow").remove();
return false;
}
alert();
return false;
});
$('.serviceRow').delegate('.service_id','change',function(){
;
var subdiv = $(this).parent().parent().parent().parent();
var cat_id = $(this).closest('.serviceRow').find('.service_id option:selected').attr('value');
subdiv.find('.service_price').val('');
//alert(cat_id);
//var a =
//alert(totalamount());
$.ajaxSetup({
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
});
$.ajax({
type : 'get',
url : 'get-orders-list-jason/'+cat_id+'',
dataType : 'json',
//date : { cat_id: cat_id},
success:function(data){
console.log(data);
subdiv.find('.service_price').val(data.service_price);
var price = subdiv.find('.service_price').val();
var qty = subdiv.find('.service_qty').val();
var total = data.service_price * qty ;
subdiv.find('.amount').val(total);
$('#total').val(totalamount());
//alert(alert(JSON.stringify(subdiv)));
},
error: function(error) {
//alert("Data retrive faield");
}
});
$(".serviceRow").delegate('.service_qty', "keyup",function(){
//alert('keyup');
var subdiv = $(this).parent().parent().parent().parent();
var price = subdiv.find('.service_price').val();
var qty = subdiv.find('.service_qty').val();
var discount = $('#discount').val();
var total = price * qty ;
subdiv.find('.amount').val(total);
$('#total').val(totalamount());
//alert('background-color');
//$("p").css("background-color", "pink");
});
$("#discount").keyup(function(){
$('#total').val(totalamount());
});
function totalamount(t){
var t=0;
$('.amount').each(function(i,e){
var amt = $(this).val()-0;
t+=amt;
});
var d = $('#discount').val();
total = t-d;
return total;
$('.total').html(t);
}
});
$('.serviceRow').each(function() {
$(this).find('select').change(function(){//alert($(this).val())
if( $('.serviceRow').find('select option[value='+$(this).val()+']:selected').length>1){
$(this).val($(this).css("border","1px red solid"));
alert('option is already selected');
$(this).val($(this).find("option:first").val());
}else{
$(this).css("border","1px #D2D6DE solid");
}
});
});
});
</script>
#endsection
Order Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Service;
use Validator;
use Illuminate\Support\Facades\Input;
use App\lib\Custom;
use App\lib\DBQuery;
use App\Order;
use DB;
use App\Orderdetail;
use App\Session;
use App\ShopInfo;
use App\Payment;
use Auth;
class OrderController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function getOrders(){
$orders = Order::All();
//return $orders;
return view('order.allorderlist',compact('orders'));
}
public function getOrderajax($cat_id)
{
$orders = Service::where('id',$cat_id)->first();
return $orders;
}
public function addOrder()
{
$services = Service::where('active_status',0)->get();
return view('order.addneworder',compact('services'));
}
public function saveOrder(Request $request)
{
if($request->discount_amount==""){
$validator = Validator::make(Input::all(), Order::$rules);
$request['discount_amount']=0;
}else{
$validator = Validator::make(Input::all(), Order::$numberrules);
}
if($validator->fails()){
$services = Service::where('active_status',0)->get();
return view('order.addneworder',compact('services'))->withErrors($validator);
}else{
$order = DBQuery::saveOrder($request);
//return $order;
$shopinfo = ShopInfo::find(1);
$total_bill_word = Custom::convert_number_to_words($number = $order->total_amount);
return view('report.invsaveprint',compact('order','shopinfo','total_bill_word'));
}
}
public function addOrderExCustomer($order_id)
{ $order = Order::where('id',$order_id)->first();
$services = Service::where('active_status',0)->get();
return view('order.addneworderexcus',compact('services','order'));
}
public function saveOrderExCustomer(Request $request)
{
$validator = Validator::make(Input::all(), Order::$rules);
if($validator->fails()){
$services = Service::where('active_status',0)->get();
$order = Order::where('id',$request->order_id)->first();
return view('order.addneworderexcus',compact('services','order'))->withErrors($validator);
}else{
$order = DBQuery::saveOrder($request);
$shopinfo = ShopInfo::find(1);
$total_bill_word = Custom::convert_number_to_words($number = $order->total_amount);
return view('report.invupdateprint',compact('order','shopinfo','total_bill_word'));
}
}
public function updateOrderById($order_id){
$order = Order::where('id',$order_id)->first();
$services = Service::All();
return view('order.editOrder',compact('services','order'));
}
public function saveUpdateOrderById(Request $request){
$validator = Validator::make(Input::all(), Order::$rules);
if($validator->fails()){
$services = Service::where('active_status',0)->get();
$order = Order::where('id', '=', $request->order_id)->first();
//return $order;
return view('order.editOrder',compact('services','order'))->withErrors($validator);
}else{
DBQuery::saveUpdateOrder($request);
$order = Order::where('id', '=', $request->order_id)->first();
//return $order ;
$shopinfo = ShopInfo::find(1);
$total_bill_word = Custom::convert_number_to_words($number = $order->total_amount);
return view('report.newinvoice',compact('order','shopinfo','total_bill_word'));
}
}
public function deliveryOrderById($order_id){
$order = Order::where('id',$order_id)->first();
//return $order;
$services = Service::All();
return view('order.deliveryorder',compact('services','order'));
}
public function saveDeliveryOrderById($order_id){
//$a = Auth::user()->is_permission;
//return $order_id;
//if(Auth::user()->is_permission==1){
Order::where('id',$order_id)
->update(array('service_status' => 3));
// }
$order = Order::where('id',$order_id)->first();
return view('order.deliveryorder',compact('order'));
}
}
**The order codes**
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
protected $table = "orders";
protected $fillable = [
'service_ref',
'service_status',
'order_create_by',
'service_crete_date',
'service_delivery_date',
'service_cus_name',
'cell_number',
'service_cus_email',
'service_cus_address',
'total_amount',
'discount_amount',
];
public static $numberrules = array(
'service_cus_name' =>'required',
'service_cus_address' =>'required',
'service_cus_email' =>'required',
'service_crete_date' =>'required',
'service_delivery_date' =>'required',
'total_amount' =>'required',
'discount_amount' =>'numeric|',
'cell_number' =>'required|numeric',
'service_quantity.*' =>'required|numeric',
'service_id.*' =>'required',
'service_measer.*' =>'required',
'service_description.*' =>'required',
);
public static $rules = array(
'service_cus_name' =>'required',
'service_cus_address' =>'required',
'service_cus_email' =>'required',
'cell_number' =>'required|numeric',
'service_crete_date' =>'required',
'service_delivery_date' =>'required',
'total_amount' =>'required',
'service_quantity.*' =>'required|numeric',
'service_id.*' =>'required',
'service_measer.*' =>'required',
'service_description.*' =>'required',
);
public function orderdetails() {
//return $this->hasMany('App\OrderDetail','fid','id');
return $this->hasMany('App\Orderdetail','order_id','id');
}
public function user() {
//return $this->hasMany('App\OrderDetail','fid','id');
return $this->hasOne('App\User','id','ser_act_create_by');
}
public function payments() {
return $this->hasMany('App\Payment','order_id','id');
//return $this->>belongsTo('App\Order');
}
}
Order Details Code
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Orderdetail extends Model
{
protected $table = "orderdetails";
protected $fillable = [
'order_id',
'service_id',
'service_price',
'service_quantity',
'service_amount',
'service_measer',
'service_description',
'service_id',
];
public function order() {
return $this->belongsTo('App\Order');
//return $this->>belongsTo('App\Order');
}
public function service() {
return $this->belongsTo('App\Service','service_id','id');
//return $this->>belongsTo('App\Order');
}
}

How to insert values to table 'users' in laravel 5.2?

I want to insert employee details username,area to the table 'users'.
I have the following codes of CreateEmployeeController and
createemployee.blade.php view file.
When I click on the menu Create Employee is will shows the following error
QueryException in Connection.php line 662:
SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'users' non unique (SQL: select * from users inner join users on users.id = users.users_id where users.deleted_at is null)
Controller file :
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\AdminController;
use App\CreateEmployee;
use App\Employee;
use App\Users;
class CreateEmployeeController extends AdminController
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//
}
public function addemployee()
{
$employee = CreateEmployee::all();
$employee =CreateEmployee::join('users','users.id','=','users.users_id')->get();
return view('app.admin.employee.employee',compact('employee','users'));
}
public function employeesave(Request $request)
{
$title = 'Add Employee';
$employee = new Employee();
$employee->name=$request->employee_name;
$employee ->area = $request->area;
$employee->save();
Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee created successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee');
}
public function updateemployee(Request $request)
{
Employee::where('id',$request->id)->update(array('name'=>$request->employee_name,'area'=>$request->area));
Session::flash('flash_notification', array('level' => 'success', 'message' => 'shop details updated successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee',array('id' => $request->id));
}
public function editemployee($id)
{
$employee = Employee::where('id',$id)->get();
return view('app.admin.employee.editemployee',compact('employee'));
}
public function deleteemployee($id)
{
$employee = Employee::where('id',$id)->get();
return view('app.admin.employee.delete',compact('employee'));
}
public function deleteconfirms($id)
{
$employee = Employee::where('id',$id)->delete();
Session::flash('flash_notification', array('level' => 'success', 'message' => 'customer deleted successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee');
}
public function destroy($id)
{
//
}
}
//view file
#extends('app.admin.layouts.default')
{{-- Web site Title --}}
#section('title') {{{ trans('site/user.register') }}} :: #parent #stop
#section ('styles')
#parent
<style type="text/css">
</style>
#stop
{{-- Content --}}
#section('main')
#include('utils.vendor.flash.message')
<div class="row">
<div class="page-header">
<h2>Add Employee</h2>
</div>
</div>
<div class="container-fluid">
<div class="row">
#include('utils.errors.list')
<form class="form-horizontal" role="form" method="POST" action="{{ URL::to('admin/addemployee') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label">Employee Name</label>
<div class="col-md-2">
<input type="text" class="form-control" name="employee_name"
required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label" for="religion">Password</label>
<div class="col-md-2">
<input type="password" class="form-control" placeholder="Password" name="password" id="password" data-parsley-trigger="change" data-parsley-required="true" data-parsley-minlength="6" data-parsley-maxlength="14" required>
{!! $errors->first('cpassword', '<label class="control-label" for="cpassword">:message</label>')!!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label" for="caste">Confirm Password</label>
<div class="col-md-2">
<input type="password" class="form-control" placeholder="Confirm Password" name="password_confirmation" id="password_confirmation" data-parsley-trigger="change" data-parsley-required="true" data-parsley-equalto="#password" data-parsley-minlength="6" data-parsley-maxlength="14" required>
{!! $errors->first('password_confirmation', '<label class="control-label" for="password_confirmation">:message</label>')!!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label">Area</label>
<div class="col-md-2">
<input type="text" class="form-control" name="area"
required placeholder="Area">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-2 col-md-offset-2">
<button type="submit" class="btn btn-primary">
Add
</button>
</div>
</div>
</form>
</div>
</div>
<div class="invoice-content">
<div class="table-responsive">
<div class="col-md-offset-2">
<table class="table table-invoice">
<thead>
<tr>
<th>Employee Name</th>
<th>Area</th>
</tr>
</thead>
</div>
</div>
<tbody>
#foreach($addemployee as $employee)
<tr>
<td>{{$employee->employee_name}}</td>
<td>{{$employee->area}}</td>
<td>
Edit
<a onclick="return confirm('Are you Sure you want to do this Action!'); style.backgroundColor='#84DFC1'; " href="employee/delete/{{$employee->id}}">delete</a>
</td>
</tr>
#endforeach
#if(!count($employee))
<tr><td>NO data found </td></tr>
#endif
</tbody>
</tbody>
</table>
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
</div>
</div>
#endsection
I can't get the full idea about your problem, but as upto me I understand that - You are using same table/column names in your join statement, you can do this as:
$employee = CreateEmployee::join('users', 'create_employees.id','=', 'users.employee_id')->get();
Hope this helps!

Resources