I have a couple of search forms in my app in which pagination works great, but when it comes to date search I only get the first page, when I try to go to the second page I get an undefined $ticket variable. When I look at the URL I can see that it doesn't take the date values with him to the next page.
Here is my code:
<tbody class="searchTable">
#foreach($ticket as $tickets)
<tr>
<td>
{{Carbon::parse($tickets->created_at)->format('m/d/Y')}}
</td>
<td>{{$tickets->id}}</td>
<td>{{$tickets->clientName}}</td>
<td>
{{Carbon::parse($tickets->dueDate)->format('m/d/Y')}}
</td>
<td>{{$tickets->refNumber}}</td>
<td>{{$tickets->invoiceNumber}}</td>
<td>{{$tickets->jobLocation}}</td>
<td>{{$tickets->workDescription}}</td>
<td>{{$tickets->jobStatus}}</td>
</tr>
#endforeach
</tbody>
{!! $ticket->appends(Request::only('_token','search'))->render() !!}
This is the controller:
$ticket = DB::table('tickets')
->whereBetween('created_at', [$newDateFrom, $newDateTo])
->orderBy('created_at', 'desc')
->paginate(10);
return view('ticketsView', compact('ticket'));
Here is my solution:
I have the same view for different search requests so I append the results to the paginator so it will have it on the next pages as well. The name is the value of the name attribute in the search form. In my case I had multiple. Here is an example:
{!! $ticket->appends(Request::only(['dateFrom'=>'dateFrom', 'dateTo'=>'dateTo', 'search'=>'search', 'filter'=>'filter', 'dueDateFrom'=>'dueDateFrom','dueDateTo'=>'dueDateTo']))->render() !!}
So now if my search results will contain in the URL dateTo and dateFrom values for example then it will be saved to all pages. It's important to understand that these values come from the name attribute of your search form.
Here is an example:
<form class="form-horizontal" role="form" method="GET" action="/ticket/searchresults" accept-charset="UTF-8" enctype="multipart/form-data">
<div class="text-centered">
<p><strong>Search by dates:</strong></p>
</div>
<div class="form-group">
<label for="filter">Select Client (optional)</label>
<select class="form-control" name="filter" type="text">
<option disabled selected> -- select client -- </option>
#foreach($selectClient as $selectClients)
<option value="{{$selectClients->name}}">{{$selectClients->name}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="dateFrom">From:</label>
<input class="datepicker2 form-control" name="dateFrom" type="text" required/>
</div>
<div class="form-group">
<label for="dateTo">To:</label>
<input class="datepicker2 form-control" name="dateTo" type="text" required/>
</div>
<button type="submit" class="btn btn-primary"><span class="fa fa-fw fa-search"></span></button>
</form>
Related
i have a multiple product when i get the default value of that product, but when i get that value in input field the default value doesn't show ?
<x-filament::page>
<form wire:submit.prevent="submit">
<div>
#if (session()->has('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
#endif
</div>
<select wire:model="user_type">
<option value="">Select User Type.....</option>
<option value="admin">Admin</option>
<option value="distributor">Distributor</option>
<option value="retailer">Retailer</option>
</select><br><br>
<input wire:model="name" type="text" placeholder="Name"><br><br>
<input wire:model="email" type="email" placeholder="Email Address"><br><br>
<input wire:model="password" type="password" placeholder="Password"><br><br>
<div align = "center">Products</div>
** #foreach($product as $val)
<br><br> {{ $val->name }} :
<input type="number" wire:model="default_price" value = "{{$val->default_price}}">
#endforeach<br><br>**
<button type="submit">
Submit
</button>
</form>
</x-filament::page>
Check these screencasts. They are very helpful! https://laravel-livewire.com/screencasts/data-binding
<input type="number" wire:model="default_price" value = "{{$val->default_price}}">
Livewire doesn't use value attribute!
If you want to update Product->default_price, you can use https://laravel-livewire.com/docs/2.x/properties#binding-models or if you want to only output the default_price, then remove wire:model.
Also #foreach($products as $val) $products should be plural,
and $val should be $product, because it is a product variable. Naming is important, if you don't want to confuse yourself and others constantly.
the whole idea is that when a user click on checkbox and save, the form should be submitted with an array containing the checked values, and save them in the database as single row for each value. i don't know if this is possible but i'm sure you guys have a solution or can help me?
and here's my form:
<div class="">
<form style="width: 70%" method="POST" action="{{ URL('/admin/projects/services/save') }}"
enctype="multipart/form-data">
#csrf
<input type="hidden" name="id" id="id" value="{{ #$id }}">
<input type="hidden" name="projectid" id="projectid" value="{{ #$projectid }}">
<div class="row topSpacer">
<div class="col-3">
<p class="bold">Selected Services: <span class="red">*</span></p>
</div>
<div class="col-9">
<input type="text" id="selectedServices" name="selectedServices" value="" readonly>
</div>
</div>
<div class="row topSpacer">
<div class="col-3">
<p class="bold">Select a service: <span class="red">*</span></p>
</div>
<div class="col-9">
#foreach ($services as $service)
<input type="checkbox" name="service" value="<?php echo stripslashes($service->id); ?>">
<label for="service"><?php echo stripslashes($service->name); ?></label>
<br>
<hr>
#endforeach
#error('service')
<span class="text-danger">{{ $message }}</span>
#enderror
</div>
</div>
<div class="row topSpacerHuge">
<div class="col-12 textRight">
<button type="button"
onclick="window.location='{{ url('admin/projects/services/index/'.$projectid) }}'"
class="goBackBtn">Cancel</button>
<input class="saveBtn" id="saveBtn" type="submit" value="Save">
</div>
</div>
</form>
</div>
and my script to get checkboxes value:
<script>
$(function() {
$("input:checkbox[name='service']").click(function() {
$value = [];
$.each($("input:checkbox[name='service']:checked"), function() {
$value.push($(this).val());
$array = $value.join();
});
// console.log(value.join(", "));
$("#selectedServices").val($array);
})
});
</script>
for implementing checked values I recommend to use the select tag
and you can give A name attribute with [] and it will collect all of your data
for example , look at my project's file which I'm trying to collect name of some users :
<select name="users[]" id="example-with-maxHeight" class="multiselect-group" multiple >
#foreach($users as $user)
<option #if($user->average < $averageParticipate )class="alert-danger" #endif value="{{$user->id}}">{{$user->name}} - {{$user->average}}</option>
#endforeach
</select>
have attention to users[] in name attribute
now in your request you can access all of your checked items .
if we look at your code ,can be some thing like this :
<label for="service"><?php echo stripslashes($service->name); ?></label>
<select name="services[]" id="" class="multiselect-group" multiple >
#foreach($users as $user)
<option value = "{{$sevice->id}}"> <?php echo stripslashes($service->name); ?></option>
#endforeach
</select>
now in your controllers you can access them :
request->get('services');
it will give you back an array of selected items .
Notice that id attribute helps me to interact with my java script code
you can rename it to yourselves .
i work with vuejs3 and laravel 9 on one project.
i have two DB_table. Employee and company.
Company has only id and company name.
Employee contains: id, first name, last name, email, and company_id as forign key, which was joined to id in company_table.
If you want to create a new employee, you have to enter above mentioned infos and select a company name from selectbox (which is shown in previously entered companies) and save it in the table. How can I do then?
#extends('mitarbeiter.layout')
#section('content')
<div class="card">
<div class="card-header">Mitarbeiter Page</div>
<div class="card-body">
<form action="{{ url('mitarbeiter') }}" method="post">
{!! csrf_field() !!}
<label>Vorname</label></br>
<input type="text" name="vorname" id="vorname" class="form-control"></br>
<label>Nachname</label></br>
<input type="text" name="nachname" id="nachname" v-model="mitarbeiter.nachname" class="form-control"></br>
<label>Email</label></br>
<input type="text" name="email" id="email" class="form-control"></br>
<label>Company</label></br>
<select>
<option value="">------Select Company-------</option>
<option name="companyname">
{{option.companyname}}
</option>
</select></br>
</br>
<input type="submit" value="Save" class="btn btn-success"></br>
</form>
</div>
</div>
#stop
You can use foreach like this :
<select name="company" class="form-control">
#foreach ($companies as $company)
<option value="{{ $company->id }}">{{$company->name}}</option>
#endforeach
</select>
and in the controller :
$company = Companies::find($id);
$employee = new Employee();
$employee->user_id = $request->company; //name of select
$employee->company_id = $id;
$employee->save();
hope this would help
I'm trying to create a situation where a user can load a page, select a timesheet number, and then have the system delete all records associated with that timesheet number. This function loads the form page:
public function deletetimesheetLoad()
{
$timesheets = collect(DB::select("SELECT dbo.TIME.Source AS Source
FROM dbo.TIME
GROUP BY dbo.TIME.Source
ORDER BY dbo.TIME.Source ASC"));
return view('utilities/deletetimesheet',['timesheets' => $timesheets]);
}
This is the actual blade template:
<form method="post"
action="{{url('/time/deletetimesheet/process')}}"
enctype="multipart/form-data"
<div class="form-group">
<label class="col-md-12 control-label" for="TIMESHEETNUMBER">Timesheet Number</label>
<div class="col-md-12">
<select required id="TIMESHEETNUMBER" name="TIMESHEETNUMBER" class="form-control select2_field">
<option value=""></option>
#foreach ($timesheets as $row)
<option value="{{ $row->Source }}">{{ $row->Source }}</option>
#endforeach
</select>
</div>
</div>
<div id="saveActions" class="form-group">
<input type="hidden" name="save_action" value="Submit">
<div class="btn-group">
<button type="submit" class="btn btn-success">
<span class="fa fa-save"></span>
<span data-value="Submit">Submit</span>
</button>
</div>
<span class="fa fa-ban"></span> Cancel
</div>
This is the function that the form action is pointing to:
public function deletetimesheetProcess(TimesheetRequest $request)
{
DB::table('TIME')->where('Source', $request->get('TIMESHEETNUMBER'))->delete();
\Alert::success(trans('yay'))->flash();
return view('details/customershow',[]);
}
Here are the defined routes for the two functions:
Route::get('/time/deletetimesheet', 'Admin\TimeCrudController#deletetimesheetLoad');
Route::post('/time/deletetimesheet/process', 'Admin\TimeCrudController#deletetimesheetProcess');
Currently the blade template loads correctly, and does not throw an error on submit - just reloads the current page. What am I doing wrong?
I have this leftJoin in my Laravel project
products = DB::table('products')
->leftJoin('destinations','products.id','=','destinations.product_id')
->get();
Tables:
Product: id,name Destinations:id,product_id,destination,quantity,target_person
but i don't knwo how to display leftJoin,(i just want to display name form product and quantity,destination ,target_person from destinations)
and i want to add new record
This is my form :
<form action="." method="POST" id="formid">
{{ csrf_field() }}
<div class="form-group">
<label for="first_name">Product name</label>
<input class="form-control" name="name" >
</div>
<div class="form-group">
<label for="last_name">Quantity</label>
<input class="form-control" name='quantity'>
</div>
<div class="form-group">
<label for="last_name">Destination<label>
<input class="form-control" name='Destination'>
</div>
<div class="form-group">
<label for="last_name">Target Perosn</label>
<input class="form-control" name='target_person'>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
i never do this,please help me this,im beginner in this.
As you have mentioned, I just want to display name from product and quantity,destination ,target_person from destinations. You have to use table alias like:
products = DB::table('products as t1')
->leftJoin('destinations as t2','t1.id','=','t2.product_id')
->select('t1.name', 't2.quantity', 't2.destination', 't2.target_person')
->get();