Missing understanding for pivot tables on Laravel - laravel-5

I know the relationship with table pivot, but i don't understand:
Is the pivot a table that I have to create on my database? Or is it a virtual table that laravel provides to us?!
Beyond that: is better use pivot relationship or use my own third table to relationship many to many?

You will likely only need a pivot table for a Many To Many Relationship, if it is a One to Many you would only need to include a foreign key. However, Laravel is flexible enough to allow you to do whatever you feel like doing as there is no right way to do anything in Laravel.
Personally, I would say it's better to stick to the best practices/conventions as you will find it easier to get help form the community than if you roll your own custom solution that no one else understands.
If you haven't already heard about Laracasts, it's a truly fantastic resource for building things with Laravel. I have been using Laravel for several years now and I still learn new things watching Jeffrey's videos.
If you can't afford the subscription, you can still watch each "What's new in Laravel" for free going back to Laravel 5.0 or further but I don't know how useful they would be. Which should give you a good overview of some of Laravel's best practices and conventions.
Jeffery also has a free series on Learning Vue.js 2 which you should also look into and he'll get to using Vue together with Laravel.

Related

Is there a lib for laravel or lumen 8 to handle filtering for any table?

If I have n tables in laravel and need list with filtering on all of them...Is there a lib that can do this magic without having to code the filters for each table?
Edit.
I forgot to mention that it should handle filters ALSO on relations.
Magic is not the solution, instead put some work on it.
I'm happy to announce that there is such a library now. But it is not public (and maybe will never be with this kind of attitude towards "magic"). If the laravel/lumen community is curious about it, lets talk.
Key features:
Crud REST operations including filtering capabilities (by any column) over max 9 tables via laravel/lumen relations (including these ones How to create Laravel 8 custom relation HasManyThrough 2 and 3 Link Tables so involving 4 or 5 tables in total?). Filtering includes: in, not in, starts with, contains, from, to, is null,is not null, multi-sorting filters on the resource's relations etc.
It can be used together with https://github.com/jarektkaczyk/eloquence/wiki/Mappable to not expose column names from db to FE.
PS. May I remind you that the question was: "Is there a lib for laravel or lumen 8 to handle filtering for any table?" So the answer is: YES there is (this PS if just for haters).

Laravel Modeling System

I have been using Laravel for a couple weeks now and I love the framework. However, with models is there any actual robust system? Creating models, like the user model, just seems to be string arrays of what you do and do not want modified in queries. The place I see validation of the models is in the controller (through $this->validate()) and/or migrations creating the tables.
I just wanted to know if there is a certain place I am missing or not implementing. My brain is referencing something like ASP.NET's decorators that add validation to data models. Thank you!

Model with multiple tables

We run two websites, A and B. Each website has its own table, _a_ and _b_ which have exactly the same structure. Yes, I know it's silly, we'll be rewriting them over the course of this year and next.
Using Laravel I need to create a model that will hold both tables content. I don't need any kind of UPDATE or INSERT functionality, I just need to SELECT and use with to access other model information.
Is this possible with Laravel 4.1? I can individually model each table, but that would make it difficult in the future.
I was able to fix this by making using the Repository pattern and merging the results of each model into the get and all functions.

How to process 1 form across 2 controllers/models in MVC (CFWheels)?

I'm an old CFML developer, new to CF on Wheels and MVC programming in general. I'm picking it up pretty quickly, but one thing that isn't evident to me is how one can offer a form to optionally update multiple db table records (models). I'd specifically like to set up a tabbed form for User info and User Profile info, where the former is required and the latter is not. This data is stored in two different one-to-one tables. What's the setup I need in order to call two "new" or "edit" views, run 2 "create" or "update" procedures, affecting two different tables. Or am I thinking about this all wrong.
Update: Adding some more info on what I'm trying to do. To keep it simple, I'll stick to 2 tabs and 2 tables, though I'm really looking at at least 3 in this instance.
So I've got a Users table and a UserProfiles table, and I've got models named User.cfc and UserProfile.cfc that are related 1-to-1, with UserProfile dependent on User. Pretty standard stuff. For each I've got controllers: Users.cfc and UserProfiles.cfc, each of those containing actions. add, edit, create, update, doing the obvious stuff (add and edit display forms). I have partials that display the add/edit form fields for each, so that's already prepared. Now, I want to create what is effectively a single add/edit form that can update both tables at the same time. The tabs don't really matter; effectively it could all be on one page.
So conceptually I'm doing something like:
#startFormTag(action=???)#
#includePartial("form_user_add-edit")#
#includePartial("form_userprofile_add-edit")#
<button type="submit" class="btn">#operation#</button>
#endFormTag()#
Do I need to create a separate controller action that basically combines the create and update actions for two different controllers?
Thanks in advance from a pleased and eager CFWheels newbie...
Brian
If all of the data is related through hasMany or hasOne associations, I'd recommend looking at nested properties.
http://cfwheels.org/docs/1-1/chapter/nested-properties
If you're a newbie though, you may want to refrain from this until you've got something simpler worked out.
I guess you are talking about two models representing these two tables, possibly associated using hasOne. Models allow you to validate data, this makes controller much simpler. This way you could create two forms under two tabs, and keep record's primary key as hidden field. Controller could run the validation and re-display the forms (partials may help)... Hold on, I am just going through the reference.
I realize this answer is pretty generic, as well as your question. I suggest you to go ahead and try something, see how it works.
After that update your question with code samples and ask if you have some specific problems. For example, validation and displaying errors in CFWheels may be a bit tricky.

What table naming convention is best for ORM

I recently started work at a new shop that uses a table naming convention like the following:
Users
UserRoles
UserUserRoles
UserProfiles
UserProfileLanguages
The convention I've been using is:
Users
Roles
UserRoleMaps
Profiles
Languages
When my boss asked why I don't prefix my tables, I explained that a database diagram would explain all the relationships much better than any naming convention could. I'm I wrong to assume that?
I'm willing to admit that the first example is more complete (especially if you're only looking at the tables directly), but what's the preferred solution for ORM? For example, in LINQ I would access my user's language like so:
User.Profile.Language
whereas, the first example would be:
User.UserProfile.UserProfileLanguage
Sure, I could easily rename my tables in the LINQ designer to whatever I please, but that quickly becomes a hassle if the data schema keeps changing.
EDIT: Removed APP_ prefix in example because it's not relevant to this question.
I could easily rename my tables in the LINQ designer to whatever I please

Resources