implementing crm with laravel models

Implementing CRM System With Laravel Part 3: Models and Relations

In this part of the series (Implementing CRM with laravel) we will generate the eloquent models and setup up relations between tables.

 

 

Series Topics:

 

Let’s generate the eloquent models using the laravel artisan commands, at first create a new directory inside the app/ directory called “Models“. This directory will contains our models, next run these commands one after the other:

Now after we generated the models we will list all the model code below along with the relations according to the Database Diagram that we created in the previous part2.

 

app/Models/Contact.php

app/Models/ContactDocument.php

app/Models/ContactEmail.php

app/Models/ContactPhone.php

app/Models/ContactStatus.php

app/Models/Document.php

app/Models/DocumentType.php

app/Models/Setting.php

app/Models/Task.php

app/Models/TaskDocument.php

app/Models/TaskStatus.php

app/Models/TaskType.php

app/User.php

As shown the code the relations is self explanatory as most of the relations is a one to many relationships like createdBy(), modifiedBy(), assignedTo() and there are some of them which is a many to many like Contact::documents() and Task::documents().

 

The most important part is the relations in the user model, as a sales person i must have the capability to view my contacts, leads and opportunities also view my tasks whether completed or pending, for this reasons we add relations like User::contacts(), User::leads(), User::tasks, etc.

Now let’s move on to the next part to prepare the authentication.

 

Continue to Part 4: Preparing login page

 

Share this: