I am using Crinsane Laravel in my ecommerce project. I want to add the cart products as an order in the order table. I have used foreach function in the OrderController: use AppModelsOrder; public …
Tag: eloquent
Laravel eloquent update column using relationship column
How can achieve this query? Sale::with([‘catalog’]) ->whereIn(‘id’, $ids) ->update([‘price’ => DB::raw(‘catalog.price’)]); This is not working, it shows undefined table… I tried to …
Get all data where pivot id (Laravel)
Is there the best way/the simplest way to get all data where pivot? I tried this $article = Article::with(‘category’)->wherePivot(‘category_id’, $category)->get(); but i got error The relation is many to many Article id content Articles_Has_Categories id article_id category_id Category id name Answer Please try this:
How to establish a one-to-many relationship to a model whose type is stored in db
I have a database that looks like this: Database Graphical Representation The dance_performer.perfomer_type field hosts values such at ‘AppDancer’, ‘AppCouple’ or ‘AppFormation’. How would you proceed to connect the dance_performer.perfomer_id to the different models? I am not sure how I am supposed to write the relationships in the different models. Should I create a AppPerformer model which would then direct
Get the $request object in Laravel’s model events (ex. created, updated etc.)
I am using Eloquent’s model events to do some actions after model has been created/updated/deleted. I’m refering to these: The question: I need to access the $request object in any of these. Is it possible? The scenario I am trying to do is to insert some values in another database table once the current model has been stored. The values
How To Call Procedure MySql in Laravel And Pass it to Blade.php
I got problem when i want to call procedure on MySql, this my code when i load data_saya.blade.php it’s showing an error like this but i has suplied argument foreach on my blade.php what’s wrong with my code? , Sorry for my bad english.. Answer Hi Every one this case is has been solved by doing this. Go To database.php
Laravel seeder with Eloquent give timestamp null
I am trying to insert static data, with the help of the seeder and Eloquent as bellow. Even after using Eloquent i am getting timestamp null in database. Answer The timestamp columns (created_at and updated_at) will be assigned automatically only if you are using the Eloquent save() method and create method are Eloquent. While insert method is not Eloquent, it’s
Laravel Eloquent ORM: Select from two tables without using find() possible?
Basically I would like to run a very simple database select query accross two tables in mysql considering a one-to-many-relationship. categories: This table contains all product-categories. The primary key is “id”. It has one column “url” which holds the string how to access this category, e.g. “greeting-cards”. products: This table contains all products whereas each product has one category id.
fetch join table data using eloquent laravel
I am new to laravel & want to implement eloquent relationship. Let me explain. Consider I have 2 tables products product_id product_name brand_id price brands id brand_name Each product …
Get all products where average rating is equal to 5 in laravel
I have 2 Tables Products and Reviews Products hasMany reviews Reviews belongsTo Product I want to get only those product which have avg(‘ratings’) is equal to 5 from controller, I get products = Product::with(‘category’)->with(‘reviews’)->get(); now want show in blade in one part of Top Rated Products $product->reviews()->avg(‘ratings’) I used this to get average ratings for a single Product. Now I