eloquent

Laravel 5: Extend delete() on model

ⅰ亾dé卋堺 提交于 2020-05-30 13:11:43
问题 I'm using L5.3.31 and have the following models: Addon Image Relationship: // Addon.php public function images() { return $this->hasMany('App\Image'); } // Image.php public function addon() { return $this->belongsTo('App\Addon'); } I now want to extend the delete() method to delete some images that are saved on the file system when deleting an image object. To my understand, in order to do this I need to extend the delete() method on the Image model. Now, on my image model, if I try to do

Laravel 5: Extend delete() on model

生来就可爱ヽ(ⅴ<●) 提交于 2020-05-30 13:07:06
问题 I'm using L5.3.31 and have the following models: Addon Image Relationship: // Addon.php public function images() { return $this->hasMany('App\Image'); } // Image.php public function addon() { return $this->belongsTo('App\Addon'); } I now want to extend the delete() method to delete some images that are saved on the file system when deleting an image object. To my understand, in order to do this I need to extend the delete() method on the Image model. Now, on my image model, if I try to do

Call to a member function addEagerConstraints() on float LARAVEL

断了今生、忘了曾经 提交于 2020-05-28 03:19:16
问题 My objective is to get average review of the courses available. But when i am trying to get the average review of the course its throwing me an error saying "message": "Call to a member function addEagerConstraints() on float" My Course Model public function rating(){ return $this->hasMany(Rating::class); } public function averageRating(){ return round($this->rating()->avg('ratings'),1); } Rating model public function user(){ return $this->belongsTo(User::class); } public function course(){

how to perform additional inner join on pivot table with laravel eloquent

左心房为你撑大大i 提交于 2020-05-25 08:07:30
问题 I have four tables: foods: id, name users: id, name mealtypes: id, name food_user: id, food_id, user_id, mealtype_id foods and user have a many-to-many relationship mealtype has a one-to-one relationship with food_user In the end I would like to have an instance of a model with the following properties: food.name, users.name, mealtype.name normal sql would be: SELECT f.name, u.name, m.name FROM foods f INNER JOIN food_user fu ON f.id = fu.food_id INNER JOIN users u ON fu.id = u.id INNER JOIN

Eloquent relationships laravel

我们两清 提交于 2020-05-19 03:59:27
问题 I have 3 tables categories id name categories_product id category_id product_id and a product table products id name I want products based on catergori_id, how kan i do that with laravel Eloquent? 回答1: Simple as this: Product::whereCategori_id($category)->get(); 来源: https://stackoverflow.com/questions/26920372/eloquent-relationships-laravel

Laravel relations with composite foreign keys

时间秒杀一切 提交于 2020-05-17 08:46:40
问题 Here's what I want to achieve, we have Staff and every staff can have one Position for a department, as well as one Designation for a department and multiple Additional Charges for multiple departments, one department per Additional Charge . And I want to store all the responsibilities in the staff_responsibilities table I have a staff table with the following columns id name email Then I have staff_responsibilities table with the following columns: staff_id designation_id department_id

Convert Raw SQL Query to Laravel Eloquent

╄→гoц情女王★ 提交于 2020-05-17 07:22:07
问题 My project is a content management system & a new version of it will be integrated in a Laravel framework; and there are lots of huge SQL queries which needs to be converted into eloquent syntax. I found the following tool to convert my already written queries into eloquent syntax, but it does not work. Could anyone guide me to convert my queries or help me find a tool that could do the job? Please find below a sample of my queries (note that most of my queries look similar): SELECT id, name,

How to filt data by time using Laravel?

筅森魡賤 提交于 2020-05-17 07:00:06
问题 I have this query, I would like to obtain only the data created on the current month public function index(Request $request) { if($request->ajax()) { $data = DB::table('tbl_lista_contactabilidad as a') ->select('a.id','a.rif','a.razon_social','a.postventaatcs_id','fecha_contacto','a.contactado','a.persona_contacto','a.correo_contacto','a.celular_contacto','a.numero_contacto','a.comentarios','a.auditado') ->leftjoin('tbl_equipo_postventaatcs as h','h.id','=','a.postventaatc_id') ->leftjoin(

select data no repeat in pivot table

妖精的绣舞 提交于 2020-05-16 06:32:22
问题 I have 2 table and 1 pivot table wich I use as table Historical, the column 'dateChange' indicated the store where is the employee, because i use Orderby ('dateChange','DESC') . All is ok, however how can I FILTER the results in my controller? without REPEAT records?. I need to show all the employees that belong to a unique store. I repeat again: I use 'dateChange' for i know the last store. help me, please. Thanks Pivot Table (employee_store) FK_idStore FK_idEmployee dateChange Table

Laravel - 1066 Not unique table/alias on a relationship

拈花ヽ惹草 提交于 2020-05-15 22:45:58
问题 I'm trying to create a simple relationship between tables : - attribute_type - id name - category - id name description So I created a pivot table to link them : - attribute_type_category - attribute_type_id category_id There is the model relationships : On AttributeType.php public function category() { return $this->belongsToMany('App\AttributeTypeCategory', 'attribute_type_category', 'attribute_type_id', 'category_id'); } On AttributeTypeCategory.php public function category() { return