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 Ca…
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 …
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 …
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 th…
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 a…
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 categ…
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…