I am a newbie at Laravel 6. In the view, I created a form, and when it's submitted, it should return a table filtered with the links of pagination at the bottom. All works correctly, but when I click a link of the pagination appears the following error: "Illegal operator and value combination."
I tried even using the "render" method in the view, but nothing changed. I see the links, but when I click one of them, the error appears.
View
#if (isset($meetings))
<div class="container">
<table class="table table-condensed table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Participants</th>
<th>Description</th>
<th>Room</th>
<th>Date</th>
<th>Start Hour</th>
<th>End Hour</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach($meetings as $meeting)
<tr>
<td>{{ $meeting->id }}</td>
<td>{{ $meeting->id_participants }}</td>
<td>{{ $meeting->description }}</td>
<td>{{ $meeting->id_room }}</td>
<td>{{ $meeting->date }}</td>
<td>{{ $meeting->start_hour }}</td>
<td>{{ $meeting->end_hour }}</td>
<td><button type="button" class="btn btn-primary">Edit</button></td>
<td>
<form action="{{ route('nextMeetingsDeleteMeeting', ['id' => $meeting->id]) }}" method="POST">
#csrf
{{ method_field('PUT') }}
<button type="submit" class="btn btn-danger" id={{ $meeting->id }}>Delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<div>
{{ $meetings->links() }}
</div>
</div>
#endif
Controller
public function fetch_table(Request $request)
{
$this->validate($request, [
'start_date' => 'date',
'end_date' => 'date',
]);
$start_date = $request['start_date'];
$end_date = $request['end_date'];
$participants = $request['participants'];
$room_input = $request['rooms'];
$rooms = Room::all();
$users = User::all()->where('is_active', '1')->sortBy('surname');
$meetings = $this->build_table($room_input, $start_date, $end_date, $participants);
return view('reportArea', compact('users', 'rooms', 'meetings', 'start_date', 'end_date', 'participants',
'room_input'))->withInput($request->all());
}
public function build_table($room, $start_date, $end_date, $participants)
{
if (!empty($room) && !empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('id_room', $room)
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($rooms)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where('id_room', $room)
->paginate(2);
} else {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->paginate(2);
}
return $meetings;
}
Route
Route::get('/reportarea/fetchtable', 'ReportAreaController#fetch_table')->name('reportAreaFetchTable');
Currently, all works OK, but when I click a link, the mentioned error appears. In other words, if I add the method paginate(2) I see correctly only two rows on the table, but when I click the link to see the other ones, it doesn't work correctly. Is anyone able to help me solve this problem?
You will probably need to be appending to the query string for the links for the pager to pass your other parameters you need. You are passing null as a value for those query parameters and getting the error.
As an example:
{{ $meetings->appends(['start_date' => ..., 'end_date' => ..., ...])->links() }}
Or just passing all the current query parameters (the paginator will ignore what ever key is used for the current page):
{{ $meetings->appends(request()->query())->links() }}
Laravel 6.x Docs - Pagination - Displaying Results - Appending To Pagination Links
Laravel 6.x Docs - Requests - Retrieving Input - Retrieving Input From The Query String
Related
I have the following method defined in my controller. I want to pass the value of $title along with the search results so that it can be displayed at the top of the blade page, but I am unsure how to do it.
public function index_sog(Request $request)
{
$title = 'Standard Operating Guideline';
return view('knowledgebase.index', [
'kbase' => Knowledgebase::orderBy('category', 'asc')
->filter(request(['tags', 'search']))
->where('type','SOG')
->paginate(20),
'search' => $request->input('search')
]);
}
My output...
<h4>{{//TITLE SHOULD GO HERE//}}</h4>
<div class="panel-container show">
<div class="panel-content">
#foreach ($kbase->groupBy('category') as $category => $group)
<table class="table">
<tr>
<th colspan="3" class="text-center bg-fusion-50"><strong>{{ $category }} <strong></th>
</tr>
#foreach ($group as $kb)
<tr>
<td>{{ $kb->title }}</td>
<td></td>
<td></td>
</tr>
#endforeach
</table>
#endforeach
</div>
</div>
ADD on return variables. And you can use on blade like {{ $title }}
> return view('knowledgebase.index', [
> 'kbase' => Knowledgebase::orderBy('category', 'asc')
> ->filter(request(['tags', 'search']))
> ->where('type','SOG')
> ->paginate(20),
> 'search' => $request->input('search'),
> 'title' => $title
> ]);
For example you can do this way:
return view('knowledgebase.index', [
'kbase' => Knowledgebase::orderBy('category', 'asc')
->filter(request(['tags', 'search']))
->where('type','SOG')
->paginate(20),
'search' => $request->input('search')
])->with('title', $title);
By adding the ->with() method to the return.
You can also put it inside the array of variables that you already have in return.
And then in your view:
<h4>{{ $title }}</h4>
I'm trying to update the status of a row in my Funds table using a button.
Here is my controller:
public function changeStatus(Funds $funds)
{
if ($funds > status == false) {
$funds->status = true;
$funds->update(['status' => $funds->status]);
return redirect('funds,index')->with('success', 'Good Job, Fund mark is done!');
} else {
$funds->status = true;
$funds->update(['status' => $funds->status]);
return redirect('funds.index')->with('success', ' Fund is pending!');
}
}
then I created the route for FundsController#changeStatus:
Route::patch('transactions/{funds}/completed', 'FundsController#changeStatus');
The HTML code i used in the index.blade.php file
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th style="width: 10px">Account Number</th>
<th>Other Account Number</th>
<th>Remarks</th>
<th>acc_type</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($funds as $fund)
<tr>
<td> {{ $fund->accno }} </td>
<td>{{ $fund->accnumber }}</td>
<td> {{ $fund->Remarks }} </td>
<td>{{ $fund->acc_type }}</td>
<td>{{ $fund->status }}</td>
<td>
{!! Form::model($fund, ['method' => 'PATCH', 'route' => ['funds.changeStatus', $fund->id]]) !!}
<button type="submit" class="btn btn-info">{{ $fund->status == false ? 'Marked Pending' : 'Marked complete' }}</button>
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
</table>
```
but I ended up with this error:
> Undefined property: stdClass::$slug (View: C:\Users\user pc\Desktop\dkn\resources\views\funds\index.blade.php)
Where did I go wrong and how can I update funds status using this method?
Oke you should first try to create a correct form.
First i would like to recommend you that you use named routes:
Route::patch('transactions/{funds}/completed', 'FundsController#changeStatus')->name('funds.changeStatus');
This will make it easier to get te correct route in your form.
Then the form should look something like this:
Form::model($fund, ['method' => 'PATCH', 'route' => ['funds.changeStatus', $fund->id]]);
If you want to use the slug (instead of the id):
Form::model($fund, ['method' => 'PATCH', 'route' => ['funds.changeStatus', $fund->slug]]);
When you want to use the slug, make sure to add the following method to your Funds model:
public function getRouteKeyName()
{
return 'slug';
}
Then in the controller:
public function changeStatus(Funds $funds)
{
if ($funds->status == false) {
$funds->update(['status' => true]);
return redirect('funds.index')->with('success', 'Good Job, Fund mark is done!');
} else {
$funds->update(['status' => false]);
return redirect('funds.index')->with('success', ' Fund is pending!');
}
}
OR
public function changeStatus(Funds $funds)
{
$funds->update(['status' => !$funds->status]);
if ($funds->status == true) {
return redirect('funds.index')->with('success', 'Good Job, Fund mark is done!');
} else {
return redirect('funds.index')->with('success', ' Fund is pending!');
}
}
Be sure your view address file is correct.
I want to join two tables in laravel 5.3 and fetched the value in template page .now i caught error.I have two table names as users and department.$queries = DB::getQueryLog(); return the query what I want exactly as select users.*, department.name as dept_name from users inner join department on users.department_id = department.id for the following query.this will return the error
ErrorException in Macroable.php line 74:
Method links does not exist. (View: C:\wamp64\www\testLaravel\TestTravel\resources\views\approval_view.blade.php)
BadMethodCallException in Macroable.php line 74:
Method links does not exist.
controller
class travelApprovalController extends Controller {
public function index(){
//$users = DB::table('passenger')->paginate(2);
$users = DB::table('users')
->join('department', 'users.department_id', '=', 'department.id')
->select('users.*', 'department.name as dept_name')
->get(); //->paginate(2)
return view('approval_view',['users'=>$users]);
}
approval.blade.php
#foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td><a href="#" class="viewPopLink" role="button" data-id="{{ $user->id }}" data-toggle="modal" data-target="#myModal">{{ $user->dept_name }}<a></td>
<td>{{ $user->dept_name }}</td>
<td>{{ $user->name }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
{{$users->links()}}
try this
$users = DB::table('users')
->join('department', 'users.department_id', '=', 'department.id')
->select('users.*', 'department.name as dept_name')
->paginate(2);
Use like this
#foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td><a href="#" class="viewPopLink" role="button" data-id="{{ $user->id }}" data-toggle="modal" data-target="#myModal">{{ $user->dept_name }}<a></td>
<td>{{ $user->dept_name }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->links }}</td>
</tr>
#endforeach
OR
{{$users[0]->links()}}
i am fetching values from the database and displaying it into a table using php laravel. Latitude logitude value am fetching and displaying in my table. there is another column address, so in that column i need to display the address by converting corresponding lat long value from the database. Can anyone tell how i can write the code for that?
my view blade is giving below
#extends('app')
#section('content')
</br></br></br></br></br></br></br></br>
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">Vehicle Report</li>
</ol>
<h1>Vehicle Report</h1>
<p></p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table id="example" class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Status</th>
<th>Lat/Long</th>
<th>Speed</th>
<th>Altitude</th>
<th>Odometer</th>
<th>Fuel</th>
<th>Address</th>
</tr>
</thead>
<tbody>
#foreach($devices as $device)
<tr>
<td>{{ date('Y/m/d H:i:s',($device->timestamp)) }}</td>
<td>{{ date('H:i:s',($device->timestamp)) }}</td>
<td>{{--}}{{ $device->statusCode }}--}}
#if($device->statusCode == '61715')
Stop
#elseif($device->statusCode=='62465')
Ignition_On
#elseif($device->statusCode=='61713')
Start
#elseif($device->statusCode=='61714')
InMotion
#elseif($device->statusCode=='62467')
Ignition_Off
#else
Speeding
#endif
</td>
<td>{{ round($device->latitude,5).'/'.round($device->longitude,5) }}</td>
<td>{{ $device->speed }}</td>
<td>{{ round($device->altitude) }}</td>
<td>{{ round($device->odometer) }}</td>
<td>{{ ($device->fuelLevel*100).'%' }}</td>
<td>{{ ?????????? }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</br>
</br></br></br></br>
Controller page is
class ReportController extends Controller
{
public $type = 'Device';
public function getAdd()
{
$vehicles = DB::table('device')->get();
return view('reports.vehicleDetail')->with('vehicles', $vehicles);
}
public function get(Request $request)
{
$account = Account::select('accountID')->where('accountID','=','gts')->get();
foreach ($account as $acc) {
$abc = $acc->accountID;
}
try {
$device_id = $request['deviceID'];
$from = strtotime($request['Fdate']);
$to = strtotime($request['Tdate']);
$devices=DB::table('device as b')
->join('eventdata as a', 'a.deviceID', '=', 'b.deviceID')
->where('a.deviceID', '=', $device_id)
->where('a.accountID', '=', $abc)
->where('a.creationTime', '>=', $from)
->where('a.creationTime', '<=', $to)
->select('a.accountID', 'a.deviceID', 'b.description', 'a.timestamp','a.statusCode',
'a.latitude', 'a.longitude', 'a.speedKPH as speed', 'a.heading', 'a.altitude', 'a.address', 'a.distanceKM as distance', 'a.odometerKM as odometer', 'a.IbatVolts', 'a.EbatVolts', 'a.ITempr', 'a.fuelLevel', 'a.inputState', 'a.IgnRuntime', 'GPSFixType', 'a.GPSPDOP', 'a.isTollRoad')->get();
// $devices = DB::table('eventdata')->get();
return view('reports.vehicleReport')->with('devices', $devices);
} catch (ModelNotFoundException $err) {
//Show error page
}
}
}
Thanks in advance.
You need to use Reverese Geocoding. Google maps API would be the best choice.
<?php
if(isset($_POST['latitude'])){
$lat=$_POST['latitude'];
$long=$_POST['longitude'];
$address=file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&key=YOUR_API_KEY");
$json_data=json_decode($address);
$full_address=$json_data->results[0]->formatted_address;
}
?>
I don't know what this error cause. I didn't change anything in my codes. But when I go to my search view. It always returns me the undefined property error. This error cause when I tried to foreach all my columns in my table data. I already solve this error not once. Because it cannot find the $id of selected options. But this time I can't fix it.
Error:
Undefined property: stdClass::$id (View: C:\Users\JohnFrancis\LaravelFrancis\resources\views\document\show.blade.php)
View
show.blade.php - This view will list all the values in my tables.
#section ('content')
<div class = "col-md-12">
<table class = "table">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Sender</th>
<th>Date Received</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($documentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ strip_tags(substr($list->content, 0, 50)) }} {{ strlen($list->content) > 50 ? "..." : '' }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ date('M j, Y', strtotime($list->dateReceived)) }}</td>
<td>
<button type = "submit" class = "btn btn-info">Read</button>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endsection
read.blade.php - This where it will redirect to the current view that selected.
<!--DOCUMENT CONTROLLER-->
<div class = "col-md-6">
<form class = "vertical">
<div class = "form-group">
<textarea id = "content">{{ $documentLists->content }}</textarea>
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Approve</button>
</div>
</form>
</div>
Controller
//SHOW
public function showDocuments()
{
$documentLists = DB::table('document_user')->select('documents.title', 'documents.content', 'categories.category_type', 'users.username', 'document_user.dateReceived')
//Table name //PK //FK
->join('users', 'users.id', '=', 'document_user.sender_id')
->join('documents', 'documents.id', '=', 'document_user.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->where('sender_id', '!=', Auth::id())
->where('user_id', '!=', Auth::id())->get();
//VIEW
return view ('document.show')->with('documentLists', $documentLists);
}
//READ
public function readDocuments($id)
{
//Find the document in the database and save as var.
$documentLists = Document::find($id);
return view ('document.read')->with('documentLists', $documentLists);
}
routes
Route::get('/show',
[
'uses' => '\App\Http\Controllers\DocumentController#showDocuments',
'as' => 'document.show',
'middleware' => 'auth',
]);
Route::get('/receive/documents/{id}',
[
'uses' => '\App\Http\Controllers\DocumentController#readDocuments',
'as' => 'document.read',
'middleware' => 'auth',
]);
In below you are not selecting id
$documentLists = DB::table('document_user')->select('documents.title', 'documents.
but calling in your blade {{ route ('document.read', $list->id) }}
$documentLists = DB::table('document_user')->select('documents.id','documents.title', 'documents.content', 'categories.category_type', 'users.username', 'document_user.dateReceived');
You need to select the column documents.id.But you have missed it