I’m working on a Laravel 9 project and have created a custom validation rule called ValidModelOwnership which should check that the field a user is trying to add is owned by a model based on some values passed to it. I’ve written the rule, but when debugging and outputting $model->toSql() the id is empty? What am I missing? My rule:
Tag: php
Fatal error: Uncaught mysqli_sql_exception: Unknown database ‘test_db’. I keep getting this error even though I programatically created the database
Here is the code I am not sure what is going on as I am sure i made no errors while typing. As it keeps showing me that there is an unknown database despite the fact i made a CREATE DATABASE statement. I do not know if there is something else i need to do but by all measures the
how join laravel tables to get non intersected data
in my Laravel app I have 3 tables : users, documents and type_documents, the user have multiple documents and document have one type_document I want select the types that are not used in documents table for the current user with eloquent I try with this, but it give me the used type_documents : I use Laravel version 8 Answer Have
How to get a report for an Employee for each day of the date range, also for those he has not inserted any data?
Currently, I’m building an app (API) for employee management with Laravel! I will try and explain the process step by step so you can understand what I want much easier! When you create/register an Employee you have to assign how many hours will work during the week. Example: After the employee is created he can start writing the hours he
How to push value selected from db as first if it is equal with value in other column?
I am doing autocomplete query system for cities and I have problem, that I want to prioritize main city of region from another results showed for exact phrase for ex. “%Trenc%”. If city and region are the same, I would like to place it as first result and then everything other. Trencin Trenc My idea is create another column in
Laravel 9 – implode() and whereIn
Hello i’m using query builder in my laravel app. I’m trying to use the implode() method from query builder. So for example i expect a string composed from : ‘ 2,3,4… ‘ I have to use this string in next query where i use the raw query IN (‘value’, ‘value’) I’m trying to wrap those IDs in to single quotes
Simulating SELECT YEAR(post_date) SQL query using only WP Query
I’m not entirely sure this is possible but I’m completely out of ideas. The task I’m working on requires that I specifically use WP_Query due to constraints of other efficiency plugins my organization uses. Pure and simple, I need a way to simulate the following query using WP_Query: “SELECT YEAR(post_date) FROM wp_posts WHERE post_status = ‘publish’ GROUP BY YEAR(post_date) DESC”
How to use CASE WHEN IN in Laravel database query builder
I have users table and a followers table. I’m doing a search to get all the users with a specific keyword, but I want the ones which are followers of the current user to appear first. I can get all the followers id’s in a subquery, so my idea was to do something like this: I’ve been trying to get
Error => #1242 – Subquery returns more than 1 row
I am selecting order data from my orders table with that I also need the order product’s count which contains a specific word Account TopUp 200, Account TopUp 500, Account TopUp 1000, The order contain multiple product means one order contains both(Account TopUp 200, Account TopUp 500) and other products I made a subquery for this But it gives Error:
MySQL issue on INSERT … SELECT ON DUPLICATE KEY UPDATE and LAST_INSERT_ID()
In MySQL, I have INSERT … SELECT ON DUPLICATE KEY UPDATE query as below: UPDATE: This is the result from above query. Now I want to create an array of the user_id of either the insert or the update the records. So, my expecting array should be I tried it something like this, but it doesn’t work for me. That