**Step #1: Install Laravel** Install the latest Laravel version i.e. Laravel 5.8. To do so go to the project directory and run the command: ``composer create-project --prefer-dist laravel/laravel`` **Step #2: Create Package Directory** create folder from laravel root directory with this structure: ``/packages/devlabs/todolist/src`` **Step #3: Composer Initiation** Every package should have a “composer.json” file, which will contain all the packages and their dependencies. Using terminal, navigate to our package name folder, in this chapter is ``packages/devlabs/todolist``, and run following command: ``composer init`` You will be prompted for details about the package. You can skip by pressing enter and it will intake the default values. You can change this information later in the "composer.json" file. Add below dependencies and version. > laravelcollective/html ``` { "name": "devlabs/todolist", "description": "You can create the to-do-list of your task.", "authors": [ { "name": "Jhon Duo", "email": "john@example.com" } ], "minimum-stability": "dev" } ``` **Step #4: Load the Package from the Main Composer.JSON File** Now, the "composer.json" file for every Laravel application is present in the **root directory**. We need to make our package visible to the application. Add the namespace of our package in "autoload-dev > psr-4" ``` "autoload-dev": { "psr-4": { "App\\": "app/", "DevLabs\\Todolist\\": "packages/devlabs/todolist/src/" } }, ``` Then we have to autoload our package using composer command as following: ```composer dump-autoload``` **Step #5: Create a Service Provider for Package** Simply create a TodolistServiceProvider.php class inside **src** folder. Don’t forget to use namespace based on vendor that we’ve created before. ``` increments('id'); $table->string('name'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('tasks'); } } ``` **Step #7: Create the Model for the Table** Run the following artisan command: ``php artisan make:model Task `` Now, move the "Task.php" file from app/Task.php to our package folder packages/devlabs/todolist/src/Task.php. And again, don’t forget to change the namespace of the file to "DevLabs\Todolist". ``` route('task.create'); } public function create() { $tasks = Task::all(); $submit = 'Add'; return view('devlabs.todolist.list', compact('tasks', 'submit')); } public function store() { $input = Request::all(); Task::create($input); return redirect()->route('task.create'); } public function edit($id) { $tasks = Task::all(); $task = $tasks->find($id); $submit = 'Update'; return view('devlabs.todolist.list', compact('tasks', 'task', 'submit')); } public function update($id) { $input = Request::all(); $task = Task::findOrFail($id); $task->update($input); return redirect()->route('task.create'); } public function destroy($id) { $task = Task::findOrFail($id); $task->delete(); return redirect()->route('task.create'); } } ``` **Step #9: Create a Routes File** Create a new file in "devlabs/todolist/src" folder and give the name "routes.php". Define the routes we are going to use in our package. ```
| Name | Action |
|---|---|
| {{ $task->name }} | {!! Form::open(['route' => ['task.destroy', $task->id], 'method' => 'delete']) !!} {!! Form::close() !!} |