can't refresh a page after updateing a form in laravel - laravel

hello i need to do an update inside a model using Laravel, the problem is when i click on the update button (his name in the code is Modifier) the page is not refreshing.
i have tried to work with an a tag in place of button .and with the a tag the page refresh but my data is not updating.
can someone tell me where is the problem in the code
the index view code :
<table class="table table-bordered table-left">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Email</th>
<th>Rôle</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($users as $key=>$user)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if ($user->is_admin==1)Administrateur
#else Caissier
#endif
</td>
<td>
<div class="btn-group">
<a class="btn btn-success" href="" data-toggle="modal" data-target="#edituser{{ $user->id }}">
<i class="fas fa-edit"></i>
</a>
<a href="" class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
{{-- edit model --}}
<div class="modal right fade" id="edituser{{ $user->id }}" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="staticBackdropLabel">Modifier l'utilisateur</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
#csrf
#method('put')
<div class="form-group">
<label for="name">Nom</label>
<input type="text" value="{{ $user->name }}" name="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" value="{{ $user->email }}" name="email" class="form-control">
</div>
<div class="form-group">
<label for="name">Mot de passe</label>
<input type="password" readonly name="password" value="{{ $user->password }}" class="form-control">
</div>
{{-- <div class="form-group">
<label for="name">Confirmer le mot de passe</label>
<input type="password" name="confirm_password" class="form-control">
</div> --}}
<div class="form-group">
<label for="name">Rôle</label>
<select name="is_admin" id="" class="form-control">
<option value="1" #if ($user->is_admin==1)
selected
#endif>Administrateur</option>
<option value="2" #if ($user->is_admin==2)
selected
#endif>Caissier</option>
</select>
</div>
<div >
<button class="btn btn-success btn-block">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
the controller code :
public function update(Request $request, $id)
{
$users = User::find($id);
if (!$users) {
return back()->with('Error','user created');
}
$users->update($request->all());
return back()->with('Success','user created');
}

Your button
<button class="btn btn-success btn-block">Modifier</button>,
should be
<button class="btn btn-success btn-block" type="submit">Modifier</button> in order to submit the form to your controller.

Related

insert data not working perfectly in laravel 8

Here I am doing l laravel CRUD operation.
I have a table named scores.
Schema::create('scores', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('match_id');
$table->unsignedBigInteger('team_id');
$table->unsignedBigInteger('player_id');
$table->unsignedBigInteger('scoreupdate_id');
$table->unsignedBigInteger('outby_id');
$table->timestamps();
$table->foreign('match_id')->references('id')->on('matchhs')->onDelete('cascade');
$table->foreign('team_id')->references('id')->on('teams')->onDelete('cascade');
$table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
$table->foreign('scoreupdate_id')->references('id')->on('scoreupdates')->onDelete('cascade');
$table->foreign('outby_id')->references('id')->on('scoreupdates')->onDelete('cascade');
});
Where I want to store data from the different tables so I did this with my Score.php model
class Score extends Model
{
use HasFactory;
use HasFactory;
protected $fillable =['team_id','match_id','player_id','scoreupdate_id','outby_id','out_type',
'one','two','three','four','six'];
public function team(){
return $this->belongsTo(Team::class,'team_id');
}
public function matchh(){
return $this->belongsTo(Matchh::class,'match_id');
}
public function player(){
return $this->belongsTo(Player::class,'player_id');
}
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
}
And This to my ScoreController.php
public function index()
{
$data=Score::all();
$team=Team::all();
$match=Matchh::all();
$player=Player::all();
$scoreupdate=Scoreupdate::all();
return view('admin.manage.score.index',compact('data','team','match','player','scoreupdate'));
}
public function store(Request $request)
{
Score::insert([
'match_id' => $request->match_id,
'team_id' => $request->team_id,
'player_id' => $request->player_id,
'scoreupdate_id' => $request->scoreupdate_id,
'outby_id' => $request->outby_id,
]);
$notification = array('message'=>'Scoreupdate Inserted!','alert-type'=>'success');
return redirect()->back()->with($notification);
}
And This is my index.blade.php
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">Score</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#teamModal">
+ Add New
</button>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">All score list here</h3>
</div>
<!-- /.card-header -->
{{-- card body --}}
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>SL</th>
<th>Match Name</th>
<th>Team Name</th>
<th>Player Name</th>
<th>Out type</th>
<th>Out by type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $row)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $row->matchh->match_name }}</td>
<td>{{ $row->team->team_name }}</td>
<td>{{ $row->player->player_name }}</td>
<td>{{ $row->scoreupdate->out_type }}</td>
<td>{{ $row->scoreupdate->out_by_type }}</td>
<td>
<a href="#" class="btn btn-info btn-sm edit"
data-id="{{ $row->id }}" data-toggle="modal"
data-target="#editModal"><i class="fas fa-edit"></i></a>
<a href="{{ route('score.delete', $row->id) }}"
class="btn btn-danger btn-sm" id="delete"><i
class="fas fa-trash"></a>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
</div>
</section>
</div>
{{-- insert modal --}}
<!-- Modal -->
<div class="modal fade" id="teamModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Player Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('score.store') }}" method="Post">
#csrf
<div class="modal-body">
<div class="from-group">
<label for="player_name">Match Name</label>
<select class="form-control" name="match_id" required="">
#foreach ($match as $row)
<option value="{{ $row->id }}">{{ $row->match_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Team Name</label>
<select class="form-control" name="team_id" required="">
#foreach ($team as $row)
<option value="{{ $row->id }}">{{ $row->team_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Player Name</label>
<select class="form-control" name="player_id" required="">
#foreach ($player as $row)
<option value="{{ $row->id }}">{{ $row->player_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out type">Out type</label>
<select class="form-control" name="scoreupdate_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_type }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out by type">Out by type</label>
<select class="form-control" name="outby_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_by_type }}</option>
#endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="Submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
The problem is that when I add not out in my out type box which is id(1) in scoreupdates table and add caught in my out by type box which is id(2) of my scoreupdates table
It's inserting and retrieving not out and (-) where both of them hold id(1) of scoreupdates table but I want that when I insert not out it will insert and retrieve not out and when add caught it will insert and retrieve caught.
scores table database
I think this could be wrong you are doing
<td>{{ $row->scoreupdate->out_type }}</td
<td>{{ $row->scoreupdate->out_by_type }}</td>
On both column, you are trying to retrieve data from scoreUpdate, but looking at your database it looks like they are two foreign columns and it should be some other relation from relation outby_id, not scoreupdate_id.
On model, its showing,
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
It's retriving data from scoreupdate_id not outby_id

How can I fetch detail of each perticular ID?

In My list view I have all the details of leave. But when I click on details It will display me a Pop-up. In Pop up box it has to fetch and give me all the details of particular field but instead of that it always give me details of last inserted record
Here Is code of my list file
<table id="myTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Employee Name</th>
<th>Leave Type</th>
<th>Leave Duration</th>
<th>Applied On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#if($allLeaves != null)
#foreach($allLeaves as $leave)
<tr>
<td> {{ $leave->username }} </td>
<td> {{ $leave->typeOfLeave }} </td>
<td>
{{ $leave->startDate }} To
{{ $leave->endDate }}
</td>
<td> {{ $leave->startDate }} </td>
<td>
#if($leave['status']=='Pending')
<span class="btn btn-warning">Pending</span>
#elseif($leave['status']=='Approved')
<span class="btn btn-success">Approved</span>
#else
<span class="btn btn-danger">Rejected</span>
#endif
</td>
<td>Details</td>
</tr>
</tbody>
</table>
and in same page i wrote code of fetch records
<form id="myform" class="form-horizontal" method="POST" action="{{ route('approve_leave', $leave->id) }}">
#csrf
<div class="card-body">
<div class="row">
<label class="col-md-6"><strong> Employee Name</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="emp_name" disabled value="{{$leave->username}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Leave Type</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="leavetype" disabled value="{{$leave->typeOfLeave}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Leave Duration</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="leaveduration" disabled value="{{ $leave->startDate }} To {{ $leave->endDate }}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Reason</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="reason" disabled value="{{$leave->reasonForLeave}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Applied on</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="appliedon" disabled value="{{$leave->startDate}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Action</strong></label>
<div class="col-md-6">
<select class="form-control" id="status" name="status" value="{{$leave->status}}">
<option value="Pending" selected="selected">Pending</option>
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
</select>
</div>
</div>
#endforeach
<br>
<div class="row">
<label class="col-md-6"><strong>Reason For Action</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="reason" name="reasonForAction" placeholder="Reason Of Action" style="border:none">
</div>
</div>
<br>
<div class="modal-footer">
<button type="submit" class="btn btn-info waves-effect" data-dismiss="modal">Save</button>
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Cancel</button>
</div>
</div>
</form>
And This is the code i wrote in controller file
//Code Of list view
public function listOfLeave()
{
$allLeaves = LeaveManagement::all();
return view('pages.leavelist', compact('allLeaves'));
}
//Code of click on details button and fetch record of that particular id
public function handleLeave($id)
{
$leave = LeaveManagement::find($id);
return view('pages.leavelist', compact('leave', 'id'));
}
//code of approve reject leave and change the status of leave
public function approveLeave(Request $request ,$id)
{
$leave = LeaveManagement::find($id);
$leave->status = $request->get('status');
$leave->reasonForAction = $request->get('reasonForAction');
$leave->save();
return view('pages.leavelist');
}
If you want to show data according to user's id then you have to pass each field like data-fieldname and then you can fetch that field's data as shown in script.
Button:
<button type="button"
class="btn btn-xs btn-default confirm-modal"
data-toggle="modal"
data-target="#model"
data-id="{{ $singleRecord->id }}"
data-name="{{ $singleRecord->full_name }}"
data-leave_reason="{{ $singleRecord->leave_reason }}"
data-from_date="{{ date('d-F-Y', strtotime($singleRecord->from_date)) }}"
data-to_date="{{ date('d-F-Y', strtotime($singleRecord->to_date)) }}"
>Details </button>
And add script
<script type="text/javascript">
$('.confirm-modal').click(function (event) {
$('.employee_name').text($(this).data('name'));
$('#from_date').text($(this).data('from_date'));
$('#to_date').text($(this).data('to_date'));
$('#total_leaves').text($(this).data('total_leaves'));
$('.leave_reason').text($(this).data('leave_reason'));
})
</script>
In model div, add each id to display that data.
<div class="col-md-12">
<label for="to_date">To Date:</label>
<span id="to_date"></span>
Hope this helps :)
Edit your modal button and modal id like below,
<td>Details</td>
and your modal,
<div id="details_{{ $leave->id }}" class="modal fade edit-form" role="dialog">
or you can use javascript to populate your field,
<button type="button" class="btn btn-xs btn-default confirm-modal" data-toggle="modal" data-target="#details"
data-leave="{{ $leave }}">Details </button>
<script type="text/javascript">
$(document).on('click', '.confirm-modal', function(e){
var data = $(this).data('leave');
$('#emp_name').text(data.username);
$('#from_date').text(data.from_date');
$('#to_date').text(data.to_date);
$('#total_leaves').text(data.total_leaves);
$('#leave_reason').text(data.leave_reason);
})
</script>

Laravel Bootstrap Modal Submit button not working

I'm crazy trying to make a modal window return the control to my view. The button type is submit but it doesn't launch the route. I've seen some tutorials and there, all I have to do for create is to define action as the route and have a submit button. I've seen that, no need of ajax, or I'm not aware when they wrote the code... I went to w3c and there at the "try it yourself" I agregated the submit button, and effectively the window is not closed. So I'm totally stuck, some help would be appreciated.
Part of my view
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h5">Horarios</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#create-horario">+</button>
<div class="modal fade" id="create-horario" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ModalLabel">Nuevo horario</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('horarioperiodicos.store')}}" method="post">
<!-- {{ method_field('patch')}} -->
{{ csrf_field() }}
<div class="modal-body">
<div class="form-group">
<label for="diaSemana" class="col-form-label">Día de la semana</label>
<select name="diaSemana" class="form-control">
<option value="1" selected> Lunes</option>
<option value="2" > Martes</option>
<option value="3" > Miércoles</option>
<option value="4" > Jueves</option>
<option value="5" > Viernes</option>
<option value="6" > Sábado</option>
<option value="7" > Domingo</option>
</select>
</div>
<div class="form-group">
<div style="width:50%;float:left;display:inline-block;">
<label for="HoraInicio" class="col-form-label">Hora de inicio</label>
<input type="time" id="HoraInicio" name="HoraInicio" min="9:00" max="18:00" value="09:00" >
</div>
<div align="right">
<label for="HoraFin" class="col-form-label">Hora de fin</label>
<input type="time" id="HoraFin" name="HoraFin" min="9:00" max="18:00" value="10:00">
</div>
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary" id="submitForm">Guardar</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<table class="table">
<thead class="thead-light">
<tr>
<th>Día</th>
<th>Hora de inicio</th>
<th>Hora de fin</th>
<th>Cambios</th>
</tr>
</thead>
<tbody>
#foreach($horarioPeriodicos as $horario)
<tr>
<td>
#switch( $horario->intDia )
#case( 1 )
Lunes
#break
#case( 2 )
Martes
#case( 3 )
Miércoles
#break
#case( 4 )
Jueves
#case( 5 )
Viernes
#case( 6 )
Sábado
#default
Domingo
#break
#endswitch
</td>
<td> {{ $horario->timHoraInicio }} </td>
<td> {{ $horario->timHoraFin }} </td>
<td>
<button class="btn btn-sm btn-outline-secondary">-</button> /
<button class="btn btn-sm btn-outline-secondary">Editar</button>
</td>
</tr>
#endforeach
</tbody>
</table>
</main>
HorarioPeriodicosController (don't get to it and is in my rotes list)
public function store(Request $request)
{
//
dd(1);
}
My routes list
I tryed modifying this
<form action="{{ route('horarioperiodicos.store')}}" method="post">
{{ method_field('patch')}}
for this
<form action="{{ route('horarioperiodicos.store')}}" >
etc, etc.
Something rare is that even when I do changes there, It doesn't launch errors.
Thanks a lot
You need to place your <button> inside of the <form> element.
Otherwise the form will not be triggered to submit.
Alternatively you can place the button outside of the form, but you need to include the form= attribute that corresponds with the form's id= attribute in the button element:
<form id="myform" method="post" action="{{ route('store.create') }}">
<input type="text" name="name" />
</form>
<input type="submit" form="myform" />

When I click on edit button give me error

When I click in edit button it gives me a error, what is problem I can not understand now, please help me
Trying to get property 'id' of non-object (View: C:\xampp\htdocs\ytl\resources\views\profile\edit.blade.php)
This is my userprofilecontroller
public function edit( Request $request, $id){
$user_profile_id = UserProfile::where('id', '=', $id)->firstOrFail();
$exchanges = Exchange::pluck('exchange','id')->all();
$markets = Market::pluck('market','id')->all();
$countries = Country::pluck('country','id')->all();
$brokerage_company = BrokerageCompany::pluck ('brokerage_company','id')->all();
$user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile_id','exchanges','markets','countries','brokerage_company','user_profile'));
}
public function update(Request $request, $id){
$user_profile_id = UserProfile::findOrFail($id);
$input = $request->except( 'brokerage_company','user_profile');
$user_id = $user_profile->update($input);
return redirect('/profile');
}
This is profile\index.blade.php file
<div class="card card-table">
<div class="card-header">Basic Tables
<div class="tools dropdown"><span class="icon mdi mdi-download"></span><a class="dropdown-toggle" href="#" role="button" data-toggle="dropdown"><span class="icon mdi mdi-more-vert"></span></a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Another action</a><a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div><a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th style="width:10%;">Country</th>
<th style="width:10%;">Exchange</th>
<th class="number">Market</th>
<th class="number">Company</th>
<th class="actions">Charges</th>
</tr>
</thead>
#if($user_profile)
<tbody>
#foreach($user_profile as $user_profiles)
<tr>
<td>{{$user_profiles->country->country}}</td>
<td>{{$user_profiles->exchange->exchange}}</td>
<td>{{$user_profiles->market->market}}</td>
<td>{{$user_profiles->brokerage_company->brokerage_company}}</td>
<td class="cell-detail"><span>Intaday-charge</span>{{$user_profiles->charge_intraday}}
<span class="cell-detail-description">Delivery-charge</span>
{{$user_profiles->charge_delivery}}</td>
{{--<td>{{$user_profiles->charge_per_lot}}</td>--}}
{{--<td>{{$user_profiles->charge__per_order}} </td>--}}
<td> <a class="btn btn-info btn-sm" href="{{route('profile.edit', $user_profiles->id)}}">Edit</a></td>
</tr>
#endforeach
</tbody>
#endif
</table>
</div>
</div>
This is profile\edit.blade.php file
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Charge</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{--<form method="PATCH", id="form", action="{{action('Profile\UserProfileController#update',$user_profile_id->id)}} ", accept-charset="UTF-8">--}}
{{--{{ csrf_field() }}--}}
{{--{{ method_field('PATCH') }}--}}
{!! Form::model($user_profile,['method'=>'PATCH', 'action'=> ['Profile\UserProfileController#update',$user_profile->id]]) !!}
<div class="row">
<div class="col-md-6 mb-3 form-group">
Country:<select name="country_id" id="country" class="form-control " onchange="myfunc()" >
<option value="">Select</option>
#foreach($countries as $key=>$val )
<option value="{{ $val->id }}">{{ $val->country }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Exchange:<select name="exchange_id" id="exchange" class="form-control notselect" onchange="myfunc1()">
<option value="">Select</option>
{{--#foreach($exchanges as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->exchange }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Market<select name="market_id" id="market" class="form-control bindselect" >
<option value="">Select</option>
{{--#foreach($markets as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->market }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Company:<select name="brokerage_company_id" id="brokerage_company_id" class="form-control " >
<option value="">Select</option>
#foreach($brokerage_company as $key=>$val)
<option value="{{ $val->id }}">{{ $val->brokerage_company }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Intraday_charge: <input type="text" name="charge_intraday" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_delivery" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_lot" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_order" class="form-control"><br>
</div>
{!! Form::close() !!}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" value="Submit" name="form1" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
It seems like you misunderstood the Pluck method. Pluck is to take several properties out an array by their key. Nothing to do with selecting columns from a Database.
I guess you want to select a single UserProfile. And the right way of doing this is as follows:
public function edit(Request $request, $id){
$user_profile = UserProfile::findOrFail($id); // Select a UserProfile by ID or fail
$exchanges = Exchange::all('exchange', 'id');
$markets = Market::all('market','id');
$countries = Country::all('country','id');
$brokerage_company = BrokerageCompany::all ('brokerage_company','id');
// I dont know what you want with this statement?
// $user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile','exchanges','markets','countries','brokerage_company'));
}

Pass data from Modal to Laravel Controller#update

I need to update some columns from my DB using the modal... question is how do I pass the data from the Modal to the Controller#update? I can get dynamic data to the Modal, but the form action does not appear to function. Can someone help me? I'm getting really frustrated by this.
=( here is my code, that is generating the modal according:
//route
Route::resource('/dashboard', 'DashboardController');
//DashboardController.php
public function index(Request $request)
{
$equipments = Equipments::all();
$serviceProviders = ServiceProviders::all();
$engineers = Engineers::all();
$equipmentsDue = Equipments::Where('due1', '<>', '1990-01-01')
->orderBy($due1)
->get();
$customerSite = CustomerSites::all();
return view('dashboard.index', compact('sort', 'customerSite', 'equipmentsDue', 'serviceProviders', 'engineers'));
}
// /dashboard/index.blade.php
#foreach ($equipmentsDue as $equipment)
<!------modal -->
<div class="modal fade" id="myModal-{{ $equipment->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Next Due</h4>
</div>
<div class="modal-body">
<form class="app-form" id="modal-form" action="/dashboard/update/{{ $equipment->id }}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="title">Next Due*</label>
<input type="text" class="form-control" id="datepicker1" name="due1" placeholder="Next Due">
</div>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="title">Completed By:</label>
<!-- Service Provider -->
<select name="note1" class="form-control" id="note1">
#foreach ($serviceProviders as $serviceProvider)
<option value="{{ $serviceProvider->id }}">{{ $serviceProvider->name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<!-- Engineer -->
<label for="title">Engineer</label>
<select name="note2" class="form-control" id="note2">
#foreach ($engineers as $engineer)
<option value="{{ $engineer->id }}">{{ $engineer->name }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-12">
<label for="title">Comments:</label>
<textarea name="note3" class="form-control" id="note3" placeholder="comments"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-default" data-dismiss="modal">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal ends-->
<tr class="alert-danger">
<td><input type="checkbox"></td>
<td align="center">{{ date("d-m-Y", strtotime($equipement->due1)) }}</td>
<td align="center"><button type="button" class="btn btn-danger btn-xs">TMU</button></td>
<td>{{ $equipment->CustomerSites->customer->name . " -> " . $equipment->CustomerSites->sitename }}</td>
<td>{{ $equipment->CustomerSites->SiteRegions->name }}</td>
<td>{{ $equipment->sn }}</td>
<td>{{ $equipment->cap }}</td>
<td></td>
<td><button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal-{{ $equipment->id}}">COMPLETE</button></td>
</tr>
#endif
#endforeach
This correctly generates the table and the modal:
Modal
The URL for the
Why the Form action dashboard#update does not call?
Because update is actually a PUT call and since form can't do a proper PUT call towards Laravel Controller you need to do form method spoofing and use the code below:
<form class="app-form" id="modal-form" action="{{ route('dashboard', $equipment->id) }}" method="POST">
{{ method_field('PUT') }}
{{ csrf_field() }}
...
add a different rout:
Route::POST('/dashboard/update/{id}', 'DashboardController#update');
Controller:
public function update(Request $request, $id) {
$the_id = $id; //this is the id.
dd($id); //to check your id value.
}
and also try to dd() your variables/ outputs for testing . . .

Resources