Laravel Livewire TypeError - laravel

I'm loading messages from the database. When first loaded, only the messages with the date of today are loaded.
public function mount() {
$this->today = Carbon::now()->format('Y/m/d');
$this->selectedDatum = $this->today;
}
And in the render method:
$logitems = Logmelding::where('datum',$this->selectedDatum)
->orderBy('datum','desc')
->paginate(10);
Works fine.
There is a Datepicker on the page to select other dates (with wire:model:"selectedDatum'). Works fine as long as I select dates that have entries in the database.
When I choose a date that has no entries in the database, of course nothing gets rendered in the foreach loop. However, when after that I choose a date that does have entries in the database, the messages are not loaded.
The console gives the following message:
Uncaught (in promise) TypeError: Illegal invocation

Related

Calling of afterSave method in application.php file slowing down complete platform and showing memory_limit exceed error

I am calling afterSave method in application.php to perform action on all models saving event. Issue is whenever I using SAVE method inside afterSave method application showing fatal error:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
Point is same method working fine in specific model, without any memory exhausted error, I think there is something that need to be fixed over database connection. Below is the code which one I am trying.
//Application.php file
namespace App;
...
...
\Cake\Event\EventManager::instance()->on(
'Model.afterSave',
function (
\Cake\Event\EventInterface $event,
\Cake\Datasource\EntityInterface $entity,
\ArrayObject $options
) {
$auth_data = isset($_SESSION['Auth'])?$_SESSION['Auth']:[];
$ActionLogs = TableRegistry::get('ActionLogs');
$ActionLogsEntity = $ActionLogs->newEmptyEntity();
$ActionLogsEntity->change_log = $change_log;
$ActionLogsEntity->action_taken_by = $auth_data->username;
$ActionLogs->save($ActionLogsEntity); //This statement working fine in specific modelTable
class Application extends BaseApplication
implements AuthenticationServiceProviderInterface
{
...
...
}
Aside from the fact that the code should go into the Application class' bootstrap() method as mentioned in the comments, when you save inside of an afterSave event that listens to all models, then you naturally create a recursion, as saving the log will trigger an afterSave event too.
You have to put a safeguard in place that prevents the logging logic from running when the afterSave event belongs to the logging model, for example:
if ($event->getSubject() instanceof \App\Model\Table\ActionLogsTable) {
return;
}
// ...

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.

Call to undefined method My_model::remove_user() Codeigniter

So I am trying to create a function that allows a user to delete their account: hence I want the function to delete all data in the database related to their profile, etc.
In view I have this button:
Delete Account
Which lead to my controller "Profiles" which has the following code:
function remove_user()
{
$this->load->model("profiles_model");
$email = $this->session->userdata('email');
$this->profiles_model->remove_user($email);
$this->load->view('templates/header');
$this->load->view('pages/homepage');
$this->load->view('templates/footer');
}
Which calls my model Profiles_model which has the following code:
function remove_user($email)
{
$this->db->where('email', $email);
$this->db->delete('profiles');
}
The table where the data is stored is "profiles".
I am also using sessions to pull the user's email.
When I execute, I get this error message: "Message: Call to undefined method Profiles_model::remove_user()"
I dont understand, as I use almost identical code to "Update" user data, and it works perfectly.
So I figured it out...my closing "}" tag on my model was ABOVE my function I was trying to call!!!!!!!!! There is 4 days wasted I will never get back again.

how to load different data tables in different tabs?

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.

CI Session is not working

We are using CI (ver 2.2.1). We are creating a session, based on url and based on session value, we do some functionalists in Controller and send to view. When we hit the view, undefined error is coming at very first time. when i refresh the page, the view load properly.
We are creating the session in Modal file:
$this->session->set_userdata('url_data',$total_result);
$total_result has array value.
My Controller:
if(isset($plan_id) && $plan_id!=''){ .... }
else {
$sessData = $this->session->userdata('url_data');
$planid = $sessData['id'] ;
$plan_details = $this->mymodel->modelname("...where id = $sessData['id']")
}
Very first time, I had a Error like
Undefined index: id

Resources