473,320 Members | 1,949 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,320 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 1083

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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.