My guess was to use the following syntax: MyModel::all()->delete(); But that did not work. I’m sure it’s super simple, but I’ve searched for documentation on the subject and can’t...
I have the following query: $query = UserSubject::where('user_id', Auth::id())->select('subject_id')->get(); and as expected I get the following result: [{"user_id":8,"subject_id":9},{"user_id":8,"subject_id":2}] Is there a way of copying the above result into another...
I’m having trouble to write query in laravel eloquent ORM. my query is SELECT book_name,dt_of_pub,pub_lang,no_page,book_price FROM book_mast WHERE book_price NOT IN (100,200); Now I want to convert this query...
When I went through Laravel Document about Eloquent ORM topic part, I got a new term “Mass Assignment”. Document show How to do Mass Assignment and the $fillable or...
When I delete a row using this syntax: $user->delete(); Is there a way to attach a callback of sorts, so that it would e.g. do this automatically: $this->photo()->delete(); Preferably...
How can we perform bulk database insertions in Laravel using Eloquent ORM? I am working with an XML document, looping through its elements. I want to accomplish something like...
I would like to retrieve the last file inserted into my table. I know that the method first() exists and provides you with the first file in the table...
lets say I have 7 columns in table, and I want to select only two of them, something like this SELECT `name`,`surname` FROM `table` WHERE `id` = '1'; In...
I’m trying to create foreign keys in Laravel however when I migrate my table using artisan i am thrown the following error: [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add...
This question already has answers here: Laravel Eloquent: Ordering results of all() (12 answers) Closed 6 years ago. Simple question – how do I order by ‘id’ descending in...