I want to do the following SQL query using the Laravel query builder: I tried with the following code but it doesn’t work correctly: I reiceived the following error: Can help? Answer Aggregate functions like sum,count,min,max,avg when selected with other columns it must have a groupBy clause for one of …
Tag: laravel
How to use where condition in if statement which is already written in codeigniter
I have got a situation where the $user_id parameter is optional and I used to do this in codeigniter in the way written below. But I am not able to figure it out, How can I write this query in laravel’s eloquent and query builder as well. Any help is much appreciated. Thanks Answer Using Eloquent: Using…
how to successfully add a foreign key constraint to your Database table in laravel using eloquent?
I have a database containing two Tables(students, payments) with id as primary key and another column studentID within the students Table. Am making studentID a foreign key in payments Table. I am getting this error message: SQLSTATE[42000]: Syntax error or access violation: 1072 Key column ‘studentID&#…
Multiple form submit in Laravel
Good day everyone, I have a form with multiple inputs in it and I want to pass it onto the database on submit. Here’s what my blade.php looks like: on code: Here’s my attempt to find a solution: on my controller: I’m having the following errors: ErrorException Array to string conversion and …
Laravel Dynamic DB Relation
I didn’t find any solution so i am asking it here.. The id of Team is related with teams in Match ,for this the solution is easy.. but The Problem is that one Match can have 3/4+ no of teams So i have to make it dynamic … Answer As Per @maki10 The working Solution Is
Laravel sql table error when i try to upload
This is the error i get SQLSTATE[HY000]: General error: 1 table posts has no column named caption (SQL: insert into “posts” (“caption”, “image”, “user_id”, “updated_at”, “created_at”) values (Caption, Why is that post table code blade.php…
Convert this SQL into eloquent ORM
I want to convert the following sql statement into eloquent: I did this as like below: The problem is that it is converting to the same sql but showing error. The error is shown below: * order_number, order_id, sum(quantity) as qty, sum(price) as pr from orders right join order_details on orders.id = order_de…
Laravel 6 many to many relationship
In laravel 6, I have 2 models I have third model to join tables Now how can I get all the teachers those are not subscribed by a particular student? For example: Teacher1, Teacher2, Teacher3, Teacher4 are in the Teacher table and Student1, Student2, Student3, Student4 are in the Student table Student1 subscri…
Is it possible to translate this “join” and “as” query to Laravel PDO functions?
I am struggling to make this SQL query to a Laravel PDO query. Does anyone know how I can do this? (Especially the ‘AS’ statements and the naming in the joins). Query: Answer Directly use join() and select() method like this:
converting datetime field to date in sql query in laravel contorller
i have to execute an sql query into laravel controller the query inclueds where caluse in which it compares a field from database which is in datetime type with another field that i get from the blade which has a date type, so i have to convert the database field from datetime type to date type this is my que…