How to build a Project Management App in Laravel 5 – Part 7

When you click on a project to see the details, it shows the tasks, files and comments form.

Let’s see how we can add tasks to each Project.

Create a new folder named tasks in the views directory and create a form.blade.php inside the tasks directory.

Move the part of the show.blade.php that has to do with the task form into form.blade.php file like so:


Replace the part in show.blade.php with @include('tasks.form') like so:

Go to routes.php and add this:

Create a ProjectTasksController.php and add this:

We are going to use the principle of Dependency Injection here by creating an instance of Task and passing it as an argument to postNewTask function.

Create the Task Model by creating a Task.php file in the app directory


We just wrote a query scope to get all the tasks that belongs to one Project.

Go to ProjectController.php

Import the Task by writing use Prego\Task from the top of the Controller file.

Add this function to retrieve all the tasks

Just scroll up the show function. We will call the getTasks function in the show function. We want to return all the tasks to the projects show view.

Modify the Show function to look like this:

Now, the function returns the project with all its tasks to the show view. :smile:

the form.blade.php in tasks folder will change, because we will add the ability to see all the tasks with an edit and delete button.

form.blade.php now looks like this:

Go to routes.php

Add this:

We are using Route::put because we want to carry out an update operation.

Go to ProjectTaskController.php

Add this function to get just one task for a particular project.

We are also returning the project id so that we can use it in the actual update function.

Create an edit.blade.php in the tasks folder


The edit task form will output each the name of an individual task in a text field and when the “Update task” button is clicked, it sends a PUT request to /projects/{projects}/tasks/{tasks} route


With this, if you click on the Edit link of each task, you should have something like so:

Now, let’s work on Updating each task that belongs to a Project.

Go to ProjectTasksController.php

Add the updateOneProjectTask function like so:

This validates the field and updates the tasks table with the Query Builder functionality provided by Laravel via the DB Facade.

Make sure to include use DB at the top of the Controller file just before use Auth;

Try it out, Yaaay! it updates successfully


Let’s implement the Delete functionality.

Add this to the routes.php

This will enable us to perform a delete operation on a particular task.

Go to ProjectTasksController.php

Add the deleteOneProjectTask function like so:

Go back to form.blade.php

Make sure the Delete button is looking like this:

Brace Up, Another Feature is Coming :smile:

Let’s add the ability for a user to attach files to the Project

We already have the files form.

Create a files folder in views directory

Then, go ahead to create a form.blade.php in the files folder. Let’s abstract the files form part from the projects/show.blade.php into this new form file we created.

files/form.blade.php will look like this now:

Then replace this part in the show.blade.php with @include('files.form')

Create a FilesController.php file


There are two functions here. uploadAttachments() gets the file to be uploaded, uploads them to Cloudinary and then return the link to the file. It then calls the saveUploads() which stores it in the database.

Cloudder is a Facade gotten from a package I installed. This line of code above uploads your file to a Cloudinary account.

This line of code returns the URL to the image uploaded to Cloudinary with the appropriate width and height of the image.

First, head over to Cloudinary and create an account. In your Dashboard, you will see your account details like CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET & CLOUDINARY_CLOUD_NAME

Now, go to your .env file and add this details because we’ll need them.

Replace the xxxxxx with your own details.

Go ahead and require jrm2k6/cloudder Laravel package for easily interacting with Cloudinary.

When you are done doing composer install and the package has been installed, Add the serviceProvider and aliases in your config/app.php 

Now run:

It copies the config file to the Laravel app.

Let’s go ahead and create the File Model. Create File.php


Now, let’s go back to ProjectController.php. We need to be able to view our files in show.blade.php , so we will tweak it a bit.

Add this function:

Make sure you don’t forget to require Prego\File at the top.

Tweak the show function to become like this:

We are getting the files and returning them with projects and tasks to the projects show view.

Now, head over to the routes.php file and add this:

This enables us to make a post request from the Files form to this route and upload our attachments for each project.

The middleware is there to make sure unregistered users can’t access this route.

file/form.blade.php will look like this now:

So all the files uploaded can be displayed on the page too. Awesome!

Now, test the Add Attachment functionality


Yaaay!!..It’s working.

Take a break and nod your head, then clap for yourself. You have done well by getting the basic features of Prego working properly.

In the next lesson, we will deal with Adding Comments and Collaborators to a Project.

Please let me know if you have any questions or observations, feel free to drop it in the comments section below.



Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.