{"id":26871287,"url":"https://github.com/codeadamca/laravel-blade-cms-topics","last_synced_at":"2026-05-16T13:02:12.830Z","repository":{"id":224243936,"uuid":"624084905","full_name":"codeadamca/laravel-blade-cms-topics","owner":"codeadamca","description":"A topics module for a Laravel CMS integrating with the journal module. ","archived":false,"fork":false,"pushed_at":"2025-01-26T21:32:58.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T14:11:36.480Z","etag":null,"topics":["blade","cms","laravel","php"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeadamca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-05T17:59:43.000Z","updated_at":"2025-01-26T21:33:01.000Z","dependencies_parsed_at":"2024-02-24T19:32:51.916Z","dependency_job_id":"106f4707-9c7b-4fc7-b2aa-bab9f498d0bd","html_url":"https://github.com/codeadamca/laravel-blade-cms-topics","commit_stats":null,"previous_names":["codeadamca/laravel-blade-cms-topics"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeadamca/laravel-blade-cms-topics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Flaravel-blade-cms-topics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Flaravel-blade-cms-topics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Flaravel-blade-cms-topics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Flaravel-blade-cms-topics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/laravel-blade-cms-topics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Flaravel-blade-cms-topics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268065788,"owners_count":24190190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blade","cms","laravel","php"],"created_at":"2025-03-31T07:18:59.721Z","updated_at":"2026-05-16T13:02:07.809Z","avatar_url":"https://github.com/codeadamca.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Types Module\n\nThis repo provides instrucitons for the addition of a topics module for a Laravel CMS. This new module includes a mant to many relationship with the journal module. \n\n## Database\n\nBefore we start coding the topics list and the entry add files, we need a table to store our journal topics. Creating a table with testing data requires us to create a migration, model, factory, and add some instructions to our seeding script. \n\n### Migrations\n\nBefore we make any files, use the Terminal to change the working directory to your project directory. I am using a Mac and my project folder was on my desktop:\n\n``` sh\ncd ~\ncd Desktop\ncd laravel-blade-cms\n```\n\n1. Using the Laravel Artisan tool, create a new migration file:\n\n    ```sh\n    php artisan make:migration create_topics_table\n    ```\n    \n    You will now have a new migration file named `\u003cYEAR\u003e_\u003cMONTH\u003e_\u003cDAY\u003e_\u003cSECONDS\u003e_create_topics_table.php`.\n\n2. In the new migration file, change the schema to:\n\n    ```php\n    Schema::create('topics', function (Blueprint $table) {\n        $table-\u003eid();\n        $table-\u003estring('title');\n        $table-\u003etimestamps();\n    });\n    ```\n    \n3. We also need a table to store the connections between the `topics` and the `entries`. Create one more migration:\n \n    ```sh\n    php artisan make:migration create_entry_topic_table\n    ```\n\n\u003e [!Note]  \n\u003e Laravel uses a database naming convention named [Eloquent](https://laravel.com/docs/10.x/eloquent). Eloquent states that the connection table in a many to many relationship is named using the two table names (singular).\n\n4. In the new migration file, change the schema to: \n\n    ```php\n    Schema::create('entry_table', function (Blueprint $table) {\n        $table-\u003eid();\n        $table-\u003eforeignId('entry_id');\n        $table-\u003eforeignId('topic_id');\n    });\n    ```\n    \n\u003e [!Note]  \n\u003e The foreign keys are named `\u003cTABLENAME\u003e_id`. Also note that we do not need timestamps in this table. \n    \n### Model\n\nWe need a new model to define the `topics` table relationships and rules. The model scaffolding that Artisan provides is sufficient.\n\n1. Create a new `Topic` model: \n\n    ```sh\n    php artisan make:model Topic\n    ```\n    \n2. You will now have a filed named `Topic.php` in the `/app/Models` folder. No changes needed.\n\n3. We also need to add the relationships to the `Entry.php` and `Topic.php` models. Add this method to the `Entry.php` file just after the `use HasFactory;` line:\n\n    ```php\n    public function topics()\n    {\n        return $this-\u003ebelongsToMany(Topic::class);\n    }\n    ```\n    \n    And this method to the `Topic.php` file:\n    \n    ```php\n    public function entries()\n    {\n        return $this-\u003ebelongsToMany(Entry::class);\n    }\n\n\u003e [!Note]  \n\u003e We do not need a model for the `entry_topic` table.\n    \n### Factory\n\nWe need a factory to give Laravel instructions on how to populate the `topics` table. \n\n1. Creat a new factory:\n\n    ```sh\n    php artisan make:factoryTopicFactory\n    ```\n    \n2. You will now have a filed named `TopicFactory.php` in the `/database/factories` folder. Open this file and change the definiation method return value to:\n\n    ```php\n    return [\n        'title' =\u003e $this-\u003efaker-\u003eword,\n    ];\n    ```\n    \n### Seeding\n\nLastly we need to give Laravel instructions on how many topics and connections to add. \n\n1. Open up the `DatabaseSeeder.php` file in the `/database/seeders` folder.\n\n2. At the top of the file add the entries model, add this line below `use App\\ModelEntry;`:\n\n    ```php\n    use App\\Models\\Topic;\n    ```\n    \n3. Add some code to remove existing topics when seeding is initiated. Add this below `Project::truncate();`:\n\n    ```php\n    Topic::truncate();\n    ```\n    \n    \u003e **Note**  \n    \u003e We do not need to seed or truncate the `entry_topic` table.\n    \n4. Add code to add four fake topics. Add this line before `Project::factory()-\u003ecount(4)-\u003ecreate();`:\n\n    ```php\n    Topic::factory()-\u003ecount(4)-\u003ecreate();\n    ```\n    \n5. Finally we need to add a few connections to the entries. Change the line of code that adds entries to:\n\n    ```php\n    Entry::factory()-\u003ecount(4)-\u003ecreate()-\u003eeach(function($entry){\n        $topics = Topic::all()-\u003erandom(rand(1,2) )-\u003epluck('id');\n        $entry-\u003etopics()-\u003eattach($topics);\n    });\n    ```\n    \n    This code will add four entries and then attach one to three random topics. \n    \n### Execute\n    \nLastly we need to execute our migrations and seeding. Using the Terminal (or GitBash on a Windows machine) run this comment:\n\n```sh\nphp artisan migrate:fresh --seed\n```\n\nIf you received no errors, there will be tables with data in your database. Open up phpMyAdmin to check!\n \n## List\n\nNow that the database is ready and populated, we need to create the topics list and entry add code. Let's start by adding the list.\n\n### Dashboard\n\nOpen up `dashboard.blade.php` in the `resources/views/console/` folder, and add link to manage topics. Add this line after entries.\n\n```php\n\u003cli\u003e\u003ca href=\"/console/topics/list\"\u003eManage Topics\u003c/a\u003e\u003c/li\u003e\n```\n\nOpen a browser, login to the CMS, and click `Manage Topics Entries`. You should get a `page not found` error. We need to add some new routes.\n\n### Routes\n\nOpen the `web.php` file in the routes folder. Import the `TopicsController` by adding a `use` command to the top of your file.\n\n```php\nuse App\\Http\\Controllers\\TopicsController;\n```\n\nCopy and paste one of the list routes from one of the other modules and update for `topics`.\n\n```php\nRoute::get('/console/topics/list', [TopicsController::class, 'list'])-\u003emiddleware('auth');\n```\n\nAlso add a route for the entries add form:\n\n```php\nRoute::get('/console/entries/add', [EntriesController::class, 'addForm'])-\u003emiddleware('auth');\nRoute::post('/console/entries/add', [EntriesController::class, 'add'])-\u003emiddleware('auth');\n```\n\nRefresh your browser, and you will get a new error message that states `Controller TopicsController does not exist`.\n\n### Controller and Method\n\nUse the Laravel Artisan tool to make a new controller.\n\n```sh\nphp artisan make:controller TopicsController\n```\n\nRefresh the browser and you will get a new error that states `Method TopicsController::list does not exist`.\n\nOpen up the new `TopicsCopntroller.php` file. Add a `use` command to import the Topic model.\n\n```php\nuse App\\Models\\Topic;\n```\n\nAdd a list method. This can be copied from one of the other modules and then adjusted for entries.\n\n```php\npublic function list()\n{\n    return view('topics.list', [\n        'topics' =\u003e Topic::all()\n    ]);\n}\n```\n\nRefresh the browser and you will get a new error that states `View [entries.list] not found.`.\n   \n### Views\n\nLastly we need to create a view. In the `resources/views/` folder, create a new folder named `topics` and copy the `list.blade.php` file from one of the other modules, and adjust for topics. The `types.lisst` view is probably the most similar. \n\n```php\n@extends ('layout.console')\n\n@section ('content')\n\n\u003csection class=\"w3-padding\"\u003e\n\n    \u003ch2\u003eManage Topics\u003c/h2\u003e\n\n    \u003ctable class=\"w3-table w3-stripped w3-bordered w3-margin-bottom\"\u003e\n        \u003ctr class=\"w3-red\"\u003e\n            \u003cth\u003eName\u003c/th\u003e\n            \u003cth\u003e\u003c/th\u003e\n            \u003cth\u003e\u003c/th\u003e\n        \u003c/tr\u003e\n        \u003c?php foreach($topics as $topic): ?\u003e\n            \u003ctr\u003e\n                \u003ctd\u003e{{$topic-\u003etitle}}\u003c/td\u003e\n                \u003ctd\u003e\u003ca href=\"/console/topics/edit/{{$topic-\u003eid}}\"\u003eEdit\u003c/a\u003e\u003c/td\u003e\n                \u003ctd\u003e\u003ca href=\"/console/topics/delete/{{$topic-\u003eid}}\"\u003eDelete\u003c/a\u003e\u003c/td\u003e\n            \u003c/tr\u003e\n        \u003c?php endforeach; ?\u003e\n    \u003c/table\u003e\n\n    \u003ca href=\"/console/topics/add\" class=\"w3-button w3-green\"\u003eNew Topic\u003c/a\u003e\n\n\u003c/section\u003e\n\n@endsection\n```\n\nRefresh your browser.\n\n## Add\n\nIf you haven't already, create a `topics.add` file in your views. Use the `types.add` view as a guide.\n\n\u003e [!Warning]  \n\u003e This repo still has a last few steps. Coming soon!\n   \n***\n\n## Repo Resources\n\n* [laravel-blade-cms](https://github.com/codeadamca/laravel-blade-cms)\n* [Laravel](https://laravel.com/)\n\n\u003cbr\u003e\n\u003ca href=\"https://codeadam.ca\"\u003e\n\u003cimg src=\"https://cdn.codeadam.ca/images@1.0.0/codeadam-logo-coloured-horizontal.png\" width=\"200\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Flaravel-blade-cms-topics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Flaravel-blade-cms-topics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Flaravel-blade-cms-topics/lists"}