473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Protect pivot table from mass assignment using eloquent

Hi

I have following tables:

Expand|Select|Wrap|Line Numbers
  1. document: id, name;
  2. author: id, name, job_title;
  3. document_author: document_id, author_id, position
I'm passing an array of following structure:

Expand|Select|Wrap|Line Numbers
  1. $attributes = [name, job_title, position]; 
  2.  
  3. I'm trying to create author's model and attach it to document:
Expand|Select|Wrap|Line Numbers
  1. $author = \Author::create($attributes);
  2. \Document::find($id)->authors()->save($author,$attributes);
Then I get QueryException, because laravel tries to mass assign attributes to pivot table, while it should only pass a position field.

The only I got is to filter array, like that:

Expand|Select|Wrap|Line Numbers
  1. $author = \Author::create($attributes);
  2. $pivotAttributes = array_only($attributes, ['position'])
  3. \Document::find($id)->authors()->save($author,$pivotAttributes);
Is there any better way, to define which columns of pivot table are fillable, better somewhere in the model or in it's relation?
Apr 17 '15 #1
0 1085

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ajay | last post by:
Hello all, I used to display reports in Excel earlier on my website. Now the client has requested that he would like see reports in Pivot table on the web . The backend is Sql2000. Can you please...
1
by: Grey | last post by:
I have created a asp.net form for user to input data. After input the data, user need to click a button to export the input data to excel for data analysis with excel pivot table function. is it...
1
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do...
1
by: clickon | last post by:
Does anyone know of a site outlining a good method of implementing a Pivot table style grid using aGridView control or similar?
9
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury...
0
by: salad | last post by:
I have A97 and A2003. I created a form using the Pivot Table wizard. This creates an unbound form with an embedded OLE object containing a Pivot table in Excel. There are 2 controls when the...
7
by: MMak12 | last post by:
I am trying to generate pivot table in excel using perl which brings data from MSAccess .If some body has done this before can you please help me.
0
by: ravindarjobs | last post by:
Hello friends, I am using ms access 2003, and Vb6. i am displaying a table in a form as pivot table (following "Auto Form: Pivot Table" Wizard) Usually i select the items i want to be...
2
by: dha lak | last post by:
Hi, I have 4 tables in my database. i want to create pivot table using them in a gridview. 1) Category CategoryID CategoryName 1 Milk 2 Nuts 3 Fruits
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.