my question consists of two parts:
1, I'm developing small ticketing software for technical support. I have model and views for Workorder (type of ticket). I would like to include another model's field/input into this model. This model is called WorkorderJournalUpdate. It's basicly just table with 3 rows: *id, workorder_id, text*. In this case, "workorder_id" is in HAS_MANY relation with "workorder_id" in Workorder model/table.
The reason why I want to include this field/model is to create unique journal record after each Workorder update, so it looks like this:
http://luzer.eu/pu_files/27844_RelationsTC.jpg
//Edit: It would be great, if I could add new journal entry on each page update and as well read all previous records.
2, this part of my question is simple. I would like to make rule in model to make certain
fields required, but only if other field is filled in. For example:
Order ID:
Ordered by:
If Order ID is not filled in, Ordered by should not be required. If Ordered by is filled in and Order ID is not, Order ID should be required. Is this possible with "required on" rule?
This is all, hopefully, somebody will be able to help me. Thank you in advance!
May be this like can help you
http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/
Related
I want to write a method to save the history of changes in the table. I have three tables (products, articles and categories). When a user makes a change, for example in the product name. I want to display a message at the product, example: User Jack change the name of product with "ball" on the "ball2016."
I came up with that I created new pivot table "history_products" wherein the columns will: "user_id", "products_id", "created_at" and "updated_at". This table will be connected with table products. I want to used this trigger. You think it's a good idea or in a Laravel can do it in an easier way??
a good source/library is revisionable, the following:
VentureCraft/revisionable
I have three tables which are all related to a user (they all belong to a user), as well as to each other. Some examples to show the relations:
http://www.laravelsd.com/share/R8DYhg
http://laravel.io/bin/Nkeve
I have an appointments page where a user can add an appointment, but it needs to have a label attached to it, as well as a status. A label can be something like "Personal", "Business", and a status something like "Open", "Closed", etc. The user can create the labels and the statuses themselves.
Right now I have a label_id and a status_id in the appointments table, and I query results based on the id's which are stored in there. It all works as it should be, but now I want to change my "Create Appointment" form, and make sure that users can fill out a field to create a new label or status on the fly.
My question is, can I create something better instead of the label_id and status_id in the appointments table? I am asking because with the above changes, there will be a lot of if's. For example, I need to check if the user selected an existing label/status from the dropdown, or if they entered a new label/status using the field, andperform the right save query based on those results, and so on.
I also have a contact_id or a relation_id, but I am using polymorphism for those, too bad I cannot use polymorphism for this in some way. But maybe there is a better way than what I have so far.
I'm stuck in a problem and I can't find a solution to this, it's annoying me.
I've two tables, one called contacts and the other one called phonebooks and they are linked with a third table called *contacts_phonebooks*, this is a many-to-many relationship summarize below:
contacts: id (pk)
phonebooks: id (pk)
contacts_phonebooks: contactid (fk), phonebooksid (fk)
Pretty simple and clear, and it works.
I'm using Laravel 4 and Eloquent ORM, everythings works fine when I've to fetch it, insert it and delete it but when I need to update a contact I fail miserably. I've a form that has a number of checkboxes that represent all the phonebooks (every checkbox has phonebook[] as name) so when you check one of those the phonebook id will be saved in the *contacts_phonebooks* with the contact id.
The problem is that this is not true! I mean when I run this code:
$contact = Contact::find($id);
$contact->contact_name = Input::get('newCName');
$contact->contact_surname = Input::get('newCSurname');
$contact->contact_email = Input::get('newCEmail');
$contact->contact_phone = Input::get('newCPhone');
$contact->contact_birth = Input::get('newCDate');
$contact->phonebooks()->sync(Input::get('phonebook'));
if($contact->save())
{
return "TEST DONE?";
}
It deletes every row in *contacts_phonebooks* associated with the contact id and save only the new one checked... This is weird I know, I try to explain it better.
I want to update Mr.x and he actually is in "Stackoverflow" phonebook, I want to add him in "Nerd" phonebook so I click on update and I selected "Nerd", the other one is already selected.
When I update him the system deletes the "Stackoverflow" link and save ONLY the "Nerd" phonebook (with the code above) this things driving me crazy because Laravel 4 Doc says that you should use the sync() method in order to update a many-to-many relationship.
I don't how how to solve it, I hope you will understand what's my problem.
Cheers.
The documentation says "The sync method accepts an array of IDs to place on the pivot table. After this operation is complete, only the IDs in the array will be on the intermediate table for the model:"
So what I think you are probably looking for is attach().
$contact->phonebooks()->attach(Input::get('phonebook'));
Then you will have to use detach() to remove him from the other.
As stated in the docs: The sync method accepts an array of IDs to place on the pivot table.
Your pivot table should be named
contact_phonebook
and it specifies that in Laravel's documentation.
I have a test project and I need some help. This is my URL("localhost/ums/relationscls/courseLecturer/1"). When I input "1" on the URL the controller will find student whose id is "1". It goes same with 2 or 3.
I have tables named as
courses
course_name|course_code|course_credit
students
student_name|student_number
lecturers
id|lecturer_name
relationscls
course_id|lecturer_id|student_id
I want to get student's id from the URL and match it from the relationscls table, then fetching course_id and lecturer_id from the same table.
After that, I want to fetch course_name, course_code and credit from the course table with the course_id which we found it from the relationscls table before.
How can I make it possible? Can anyone help, its emergency situation. Thanks.
You're probably looking for CakePHP's Containable Behavior. It lets you do a find then specify which related data you want to automatically retrieve.
You are probably looking to bind and unbind models dynamically. There are models behavior for this.
http://cakebaker.42dh.com/2008/02/02/attaching-and-detaching-model-behaviors-on-the-fly/ might help for you.
You'd probably like to check the HasAndBelongsToMany and 'hasMany-through' model associations in the cookbook, It might prove useful in your case.
I have some small issue with relationships with tables as below:
I have created a login and registration script which has the following
table name: members:
fields: member_id, firstname, lastname, login, password
Now i have made another table with this
table name: phone
fields: member_id, phoneid, name, number, prefix, time,total
I want to make a form whereby a admin can select the name of the client from a drop down list, and then add a record such as the number called, number prefix, total time and the amount for that period.
I dont know how to do this, please help me by creating a script or help me how to go about this.
So all the time a admin makes a form on Client A it gets added to a new row on the phone table, then i will just add a call script on the client side where they can see all the records that they have done.
Thanks please assist.
Regards
Your db design seems fundamentally flawed - the is no association between the members and the phone_numbers tables. Add a FK (member_id) to phone_numbers table.
Regards creating the front-end, there are quite a lot of libraries that have data stores (we use ExtJS), and upon flushing the store you can do the persistence with php.
Hope this helps!