Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
mascam97 committed Mar 10, 2021
1 parent ff6df53 commit d0d11f4
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 86 deletions.
110 changes: 24 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,20 @@
# Laravel8 Liveware Job Interview
# Laravel8 Liveware Publications ![Status](https://img.shields.io/badge/status-in_process-yellow) ![Passing](https://img.shields.io/badge/build-passing-green) ![Docker build](https://img.shields.io/badge/docker_build-passing-green)

_Many challenges and questions about Laravel._
_App to make publications and comments._

### Project goal by martin-stepwolf :goal_net:

Personal project to practice Liveware and get a job as Backend Developer.
This was a part of a interview where I completed some challenges and questions, you can read about it in this [file](challenges.md).

---

## Challenges :star2:

### 1. We need a platform with Laravel, it uses MySQL/MariaDB, a SMTP server for emails and Redis server. What are the steps you consider necessary to leave the application running in development mode?

- In a past way I would create the database in PHPMyAdmin with XAMPP or Heidi with Laragon, and then I update the file [.env](.env) with the credentials. For an SMTP server I would create an account in Mailtrap, copy the credentials and paste it in the sam file .env. About Redis, I have never used honestly, but it would be the same steps, create the service and paste the credentials in the file .env.

- Now I use docker, in this case Laravel Sail provide some containers for MySQL, MailHog(SMTP server for testing) and Redis server.

### 2. Imagine the next tables.

- Publication (id, title, content, user_id)
- Comment (id, publication_id, content, status)

How would you define the relationship a publication have many comments?

- Without Laravel, in the database When I create the table comments I would set the attribute publication_id in Comments as foreign key to reference the primary key id in Publication.
- With Laravel when I create the migration for the Comments I would set this relation with:
```
$table->foreign('publication_id')->references('id')->on('publication');
```

- Then in the Model with **Eloquent** I set this relation as function according how Eloquent works.
In this case for the Model Publication would be:
```
public function comments()
{
return $this->hasMany(Comment::class);
}
```
and for the Model Comment:
```
public function publication()
{
return $this->belongsTo(Publication::class);
}
```

### 3. With the last Models create a query with Eloquent that gets all the publications with commentaries that contains "Hola" and be approved.

```
<!-- TODO: Check in a real environment if it works -->
Publication::all()->commentaries
->where('status', 'approved')
->where('content', 'like', '%Hola%')
->get();
```

### 4. What are the advantages of migrations in a production server?

There are many advantages, even since development server like:

- Having a better **version control** in the database structure, if any developer create a table there are not many problem to others.
- If there are some mistake or error we can undo the last updates.
- We can test better the database before to update the tables in the production server.
In this interview they ask me to make a Laravel project with similar features that I have made in other personal projects, so I decided to challenge me by creating a project with Jetstream + Liveware - Blade, a way similar to Vue - Inertia, and Implement Tailwindcss instead of Bootstrap.

And then we just run `php artisan migrate` in the production server and we have the new updates in the database without affect the real data and avoid mistakes.
### Achievements :star2:

### 5 Create a project in Laravel.

#### Part 1. Create the tables users, publications and comments.

Ready, I added extra features like another table `comment_state` for the status in comments instead of the attribute `status`, and the table comments has the attribute `user_id`.

And I created all resources like seeders, factories, relation in the Models and some Test (some tests does not work, but to not overload me I create this commit to have less files in the stage).

#### Part 2. Create a CRUD for my publications.

With livewire I get the data with pagination, create, delete, update and look a publication. There are some validations about storing and updating data, and a basic policy to not allow delete and update publications by not owners.

#### Part 3. Create some views to look all the publications with comments.

This are static views, so I did not use livewire. All the users can look all the publications and each publication show just the approved comments.

#### Part 4. All the user can comment just one time any publication.

The resource to create the commentary and the validations were created. I also improve the seeders and factories with more data and a defined user with a publication with some commentaries.

#### Part 5. When a user comment a publication, an email is sent to the owner.

I use an Event and Listener to catch the action, then with a Notification I sent the email, and I can look it from MailHog.

To not to overload the server, these processes are executed in the background to give a fast response to the user. We can listen this processes with `sail artisan queue:listen`.
- Completed all the challenges.
- Implemented a CRUD with Livewire.
- Implemented an Event, Listener and Notification to sent an email.

---

## Getting Started :rocket:

These instructions will get you a copy of the project up and running on your local machine.
Expand Down Expand Up @@ -166,6 +88,21 @@ There are some unit testing in Models and Traits and some feature testings in co
sail artisan test
```

---
## Advanced features

### Running Queues

There are some processes to send an email when a publication has a new comment, to run it execute:

```
sail artisan queue:listen
```

Note: Remember in production the better command is `queue:work`, [explanation](https://laravel-news.com/queuelisten).

You can look the emails with MailHog, it is on the port [8025](http://localhost:8025).

---

### Built With 🛠️
Expand All @@ -188,6 +125,7 @@ This project is licensed under the [MIT License](https://choosealicense.com/lice

### References :books:

- [Livewire with Laravel Basic Course](https://www.youtube.com/playlist?list=PLhCiuvlix-rSRRmZAL2CNOMAUjgEiFoSl)
- [Laravel 8 Introduction Course](https://platzi.com/clases/intro-laravel/)
- [Test Driven Development with Laravel Course](https://platzi.com/clases/laravel-tdd/)
- [Testing with PHP and Laravel Basic Course](https://platzi.com/clases/laravel-testing/)
86 changes: 86 additions & 0 deletions challenges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
## Challenges :star2:

### 1. We need a platform with Laravel, it uses MySQL/MariaDB, a SMTP server for emails and Redis server. What are the steps you consider necessary to leave the application running in development mode?

- In a past way I would create the database in PHPMyAdmin with XAMPP or Heidi with Laragon, and then I update the file [.env](.env) with the credentials. For an SMTP server I would create an account in Mailtrap, copy the credentials and paste it in the sam file .env. About Redis, I have never used honestly, but it would be the same steps, create the service and paste the credentials in the file .env.

- Now I use docker, in this case Laravel Sail provide some containers for MySQL, MailHog(SMTP server for testing) and Redis server.

### 2. Imagine the next tables.

- Publication (id, title, content, user_id)
- Comment (id, publication_id, content, status)

How would you define the relationship a publication have many comments?

- Without Laravel, in the database When I create the table comments I would set the attribute publication_id in Comments as foreign key to reference the primary key id in Publication.
- With Laravel when I create the migration for the Comments I would set this relation with:

```
$table->foreign('publication_id')->references('id')->on('publication');
```

- Then in the Model with **Eloquent** I set this relation as function according how Eloquent works.
In this case for the Model Publication would be:

```
public function comments()
{
return $this->hasMany(Comment::class);
}
```

and for the Model Comment:

```
public function publication()
{
return $this->belongsTo(Publication::class);
}
```

### 3. With the last Models create a query with Eloquent that gets all the publications with commentaries that contains "Hola" and be approved.

```
<!-- TODO: Check in a real environment if it works -->
Publication::all()->commentaries
->where('status', 'approved')
->where('content', 'like', '%Hola%')
->get();
```

### 4. What are the advantages of migrations in a production server?

There are many advantages, even since development server like:

- Having a better **version control** in the database structure, if any developer create a table there are not many problem to others.
- If there are some mistake or error we can undo the last updates.
- We can test better the database before to update the tables in the production server.

And then we just run `php artisan migrate` in the production server and we have the new updates in the database without affect the real data and avoid mistakes.

### 5 Create a project in Laravel.

#### Part 1. Create the tables users, publications and comments.

Ready, I added extra features like another table `comment_state` for the status in comments instead of the attribute `status`, and the table comments has the attribute `user_id`.

And I created all resources like seeders, factories, relation in the Models and some Test (some tests does not work, but to not overload me I create this commit to have less files in the stage).

#### Part 2. Create a CRUD for my publications.

With livewire I get the data with pagination, create, delete, update and look a publication. There are some validations about storing and updating data, and a basic policy to not allow delete and update publications by not owners.

#### Part 3. Create some views to look all the publications with comments.

This are static views, so I did not use livewire. All the users can look all the publications and each publication show just the approved comments.

#### Part 4. All the user can comment just one time any publication.

The resource to create the commentary and the validations were created. I also improve the seeders and factories with more data and a defined user with a publication with some commentaries.

#### Part 5. When a user comment a publication, an email is sent to the owner.

I use an Event and Listener to catch the action, then with a Notification I sent the email, and I can look it from MailHog.

To not to overload the server, these processes are executed in the background to give a fast response to the user. We can listen this processes with `sail artisan queue:listen`.

0 comments on commit d0d11f4

Please sign in to comment.