how to load different data tables in different tabs? - laravel

i am using laravel data tables to generate different data table on different tabs. but it runs only query of first data table rendered to the page.i already have attached scope to data table to generate different results for different condition
i have attached ajax() method to the data table that are not displayed in the beginning of the page
controller file
public function index(UpcomingReservationDataTable $UpcomingReservationDataTable)
{
return $UpcomingReservationDataTable->render('admin.reservations.index');
}
public function getAllReservationTable(ReservationDataTable $ReservationDataTable){
return $ReservationDataTable->render('admin.reservations.index');
}
public function getPastReservationDataTable(PastReservationDataTable $PastReservationDataTable){
return $PastReservationDataTable->addScope(new PastReservationScope)->render('admin.reservations.index');
}
pastreservationdatatable query
public function query(Reservation $model)
{
return $model->newQuery()->where('pickup_date','<',date('Y-m-d'))->orderBy('id','desc')->with('customer','package','vehicle');
}

You can show first table in load tab and next change it by ajax.

You must write a function in javascript. This function should take a value. This value contains your query information. When this is clicked on any tab, this function must be executed with that value. The function of this function is to send information to the server, receive and display. Did you do these things?
The next issue is when the Ajax data is sent, if the server path is wrong, you will encounter an error. To view errors on your browser, press the combination keys CTR + Shift + i and in the menu at the top of the window, select the console to display the errors.

Related

codeigniter 4 mysqli_sql_exception #1064 in view

It's very strange for me. Because in codeigniter 4 one of my function is working in controller but not working in view. I am getting my data's from database in controller, but when I am trying to get same data from view it showing mysqli_sql_exception #1064.
Example codes:
In Controller (MyData.php)
function get_data($status){
return $this->Data->get_data($status);
}
function view_data(){
return view('user/view-data',['data'=>$this])
}
In Model (MyData.php)
function get_data($status="approved"){
return $this->select()->where('status',$status)->get()->getResultArray();
}
In View (MyData.php)
$datas = $data->get_data('approved');
Error
mysqli_sql_exception #1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*, *, *
I believe your view_data function should be
function view_data(){
return view('user/view-data',['data'=>$this->get_data('approved')])
}
Then in view just loop through the $data array
Views are places that you MUST NOT need to execute sql queries. You need to pass only data (objects, arrays, string, int, etc.) to views.

Laravel Nova Metric displaying data from other metric

I have a two Nova Trend metrics called ApiCallsPerHour and ApiCallsPerMinute, each with a simple calculate function:
ApiCallsPerHour
public function calculate(NovaRequest $request)
{
return $this->countByHours($request, ApiCall::class);
}
ApiCallsPerMinute
public function calculate(NovaRequest $request)
{
return $this->countByMinutes($request, ApiCall::class);
}
The problem is the ApiCallsByMinute trend displays always displays the trend by hours.
I have tested and both components are loaded correctly: if I change their ranges array they independently update from each other. But whatever I put in the calculate method in the ApiCallsPerMinute, it always displays the hourly trend, even if I put return 100;.
Only when I remove the ApiCallsPerHour trend from the dashboard, the ApiCallsPerMinute is displayed correctly.
Both components do not have a value returned in the cacheFor method.
It was clear I was missing something big... These components had the same uriKey 🤦‍♂️. Don't copy paste your components folks, use the php artisan nova:trend command!

use the return value of function in protactor

How Do I user the row value to pass UI Input?
I am trying to retrieve data from DB and using in UI. By using following, getting row but want make function and function return value will be use as input
Please need help on this.
function (done) {
//var query= "SELECT name FROM partstatus where rand() limit 1";
var query = "select part from parttable order by RAND() limit 1;"
conn.result(query).then(function(rows){
// This function get called, when success
console.log("Looks:",rows);
done();
},function(error){
// This function get called, when error
console.log(error);
done.fail(error);
});
}
You need to first select the input element of your HTML and then send the text that you fetch from database, using something like:
element(by.model('greeting')).sendKeys('Hello, E2E Tests');
This will get the HTML element bound to model 'greeting' and then put the text passed to sendkeys() to the HTML element.

How can i pass other data in other function in my controller to view using CI

how can i pass a value from my query to the same view in CI. I am having a situation of like this:
public function index() {
$myinfo = $this->Myprofile_model->mydata();
$data['myinfo'] = $myinfo
$this->load->view('header');
$this->load->view('myprofile',$data);
$this->load->view('footer');
}
public function getResults($id) {
$fetchdata = $this->Myprofile_model->fetchresult($id);
$data['userselect'] = $fetchdata;
$this->load->view('myprofile',$data);
}
i already load my wholepage in index. and now i want to make another function to my button which is the getResults($id) function in my controller, and i want to display my another data from database to the same page. When i do the top code, my view is duplicating, because i loaded the $this->load->view('myprofile',$data); twice.
1: Create helper function and use that function on view page.
OR
If you want records for single id then merge both function in one.
If there is many ids and you want to fetch records on click for each id then you can use ajax.
$( document ).ready(function() {
$('.class_name').click(function(){
// place your code here to fetch records.
// on success you can display the result on same page
})
});
I am Not getting clearly but here is the controller to load multiple data on view:
public function index($id) {
$myinfo = $this->Myprofile_model->mydata();
$fetchdata = $this->Myprofile_model->fetchresult($id);
$this->load->view('header');
$this->load->view('myprofile',['myinfo'=>$myinfo,'fetchdata'=>$fetchdata]);
$this->load->view('footer');
}
You can use
$this->load->view('myprofile',['myinfo'=>$myinfo,'fetchdata'=>$fetchdata,'third_data'=>$third_data.. as many as you like]);
Here in your code you are passing an id to the getResults function so if you would like to load the data form this function you can do the same with this function. or pass the id to the same index function to get the result.

submitting form values in php using ajax request

okay, so I am trying to load a user's information into form fields after the user has finished creating an account. This is sort of a "re-check your personal info" but here his previously entered values are already set. How should I do so using ajax. I want to use the prototype ajax to avoid obtrusive coding.
Again,these are the steps
1.User creates an account on signUp.php
2.He is redirected to edit.php where he checks his personal info which is set by default.
if I do this
function setFormData()
{
new Ajax.requestHTML("edit.php")
{ onSuccess:someFunction()
});
}
then how can I set the form values, like
function someFuncton(ajax)
{
$("firstname").value=??
$("lastname").value=??
$("country").value=??
}
you can in the edit.php output an xml, json or string with the values, parse it and use in your someFunction

Resources