Skip to content

Commit fe31b37

Browse files
committed
first commit
0 parents  commit fe31b37

File tree

83 files changed

+11712
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+11712
-0
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

.env.example

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_TIMEZONE=UTC
6+
APP_URL=http://localhost
7+
8+
APP_LOCALE=en
9+
APP_FALLBACK_LOCALE=en
10+
APP_FAKER_LOCALE=en_US
11+
12+
APP_MAINTENANCE_DRIVER=file
13+
# APP_MAINTENANCE_STORE=database
14+
15+
BCRYPT_ROUNDS=12
16+
17+
LOG_CHANNEL=stack
18+
LOG_STACK=single
19+
LOG_DEPRECATIONS_CHANNEL=null
20+
LOG_LEVEL=debug
21+
22+
DB_CONNECTION=sqlite
23+
# DB_HOST=127.0.0.1
24+
# DB_PORT=3306
25+
# DB_DATABASE=laravel
26+
# DB_USERNAME=root
27+
# DB_PASSWORD=
28+
29+
SESSION_DRIVER=database
30+
SESSION_LIFETIME=120
31+
SESSION_ENCRYPT=false
32+
SESSION_PATH=/
33+
SESSION_DOMAIN=null
34+
35+
BROADCAST_CONNECTION=log
36+
FILESYSTEM_DISK=local
37+
QUEUE_CONNECTION=database
38+
39+
CACHE_STORE=database
40+
CACHE_PREFIX=
41+
42+
MEMCACHED_HOST=127.0.0.1
43+
44+
REDIS_CLIENT=phpredis
45+
REDIS_HOST=127.0.0.1
46+
REDIS_PASSWORD=null
47+
REDIS_PORT=6379
48+
49+
MAIL_MAILER=log
50+
MAIL_HOST=127.0.0.1
51+
MAIL_PORT=2525
52+
MAIL_USERNAME=null
53+
MAIL_PASSWORD=null
54+
MAIL_ENCRYPTION=null
55+
MAIL_FROM_ADDRESS="hello@example.com"
56+
MAIL_FROM_NAME="${APP_NAME}"
57+
58+
AWS_ACCESS_KEY_ID=
59+
AWS_SECRET_ACCESS_KEY=
60+
AWS_DEFAULT_REGION=us-east-1
61+
AWS_BUCKET=
62+
AWS_USE_PATH_STYLE_ENDPOINT=false
63+
64+
VITE_APP_NAME="${APP_NAME}"

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/.phpunit.cache
2+
/node_modules
3+
/public/build
4+
/public/hot
5+
/public/storage
6+
/storage/*.key
7+
/vendor
8+
.env
9+
.env.backup
10+
.env.production
11+
.phpactor.json
12+
.phpunit.result.cache
13+
Homestead.json
14+
Homestead.yaml
15+
auth.json
16+
npm-debug.log
17+
yarn-error.log
18+
/.fleet
19+
/.idea
20+
/.vscode
21+
/.zed

README.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Product Catalog with Newsletter Subscription
2+
3+
This project is a Laravel application that serves as a product catalog. Users can browse products and categories, subscribe to a newsletter, and receive updates about featured products.
4+
5+
## Features
6+
7+
- Browse products and categories
8+
- Filter products and categories by name
9+
- View products and categories by slug
10+
- Subscribe and unsubscribe to newsletters
11+
- Receive a welcome email upon subscription
12+
- Weekly newsletter with featured products
13+
14+
## Requirements
15+
16+
- PHP >= 8.2
17+
- Composer
18+
- Laravel >= 11.x
19+
- MySQL or any supported database
20+
21+
## Installation
22+
23+
Follow these steps to set up and run the project locally.
24+
25+
### 1. Clone the Repository
26+
27+
### 2. Install Dependencies
28+
29+
Run the following command to install the required packages:
30+
31+
```bash
32+
composer install
33+
```
34+
35+
### 3. Set Up Environment File
36+
37+
Copy the example environment file:
38+
39+
```bash
40+
cp .env.example .env
41+
```
42+
43+
Then, update the `.env` file with your database credentials and mail configuration.
44+
45+
Generate an application key:
46+
47+
```bash
48+
php artisan key:generate
49+
```
50+
51+
### 4. Initialize the Application
52+
53+
To run migrations and optionally seed the database, you can use the custom Artisan command:
54+
55+
```bash
56+
php artisan app:init
57+
```
58+
59+
This command will:
60+
- Run all migrations.
61+
- Prompt you to run seeders.
62+
- Ask for an email and password to create a new user.
63+
64+
### 5. Start the Development Server
65+
66+
Run the following command to start the development server:
67+
68+
```bash
69+
php artisan serve
70+
```
71+
72+
You can now access the application at `http://localhost:8000`.
73+
74+
## API Endpoints
75+
76+
### Categories
77+
78+
- **List Categories**: `GET /api/categories?name=example`
79+
- **View Category by Slug**: `GET /api/categories/slug/{slug}`
80+
81+
### Products
82+
83+
- **List Products**: `GET /api/products?name=example`
84+
- **View Product by Slug**: `GET /api/products/slug/{slug}`
85+
86+
### Subscribers
87+
88+
- **Subscribe**: `POST /api/subscribe` (requires an email)
89+
- **Unsubscribe**: `DELETE /api/unsubscribe` (requires an email)
90+
91+
## Technologies Used
92+
93+
- Laravel
94+
- PHP
95+
- MySQL
96+
- Blade (for views)
97+
- Eloquent ORM
98+
- Filament (Admin panel)
99+
100+
## License
101+
102+
This project is licensed under the MIT License.

app/Console/Commands/Init.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\User;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Artisan;
8+
9+
class Init extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'app:init';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Command description';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
// Run migrations
31+
$this->info('Running migrations...');
32+
Artisan::call('migrate:fresh', ['--force' => true]); // Use --force in production
33+
$this->info('Migrations completed.');
34+
35+
// Ask if they want to run the seeders
36+
if ($this->confirm('Would you like to run the seeders?')) {
37+
Artisan::call('db:seed'); // Use --force in production
38+
$this->info('Seeders completed.');
39+
}
40+
41+
$name = $this->ask('Enter the name for the new user');
42+
43+
// Ask for email and password to create a new user
44+
$email = $this->ask('Enter the email for the new user');
45+
46+
// Validate if the email already exists
47+
if (User::where('email', $email)->exists()) {
48+
$this->error('The email is already in use. Please choose another one.');
49+
return;
50+
}
51+
52+
$password = $this->secret('Enter the password for the new user');
53+
54+
// Create the user
55+
User::create([
56+
'name' => $name,
57+
'email' => $email,
58+
'password' => bcrypt($password),
59+
]);
60+
61+
$this->info('User created successfully.');
62+
}
63+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Mail\Newsletter;
6+
use App\Models\Product;
7+
use App\Models\Subscriber;
8+
use Illuminate\Console\Command;
9+
use Illuminate\Support\Facades\Mail;
10+
11+
class SendNewsletter extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'send:newsletter';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Send newsletter to subscribers';
26+
27+
/**
28+
* Execute the console command.
29+
*/
30+
public function handle()
31+
{
32+
$subscribers = Subscriber::all(); // Cambiar aquí
33+
$featuredProducts = Product::featured()->get();
34+
35+
foreach ($subscribers as $subscriber) {
36+
Mail::to($subscriber->email)->send(new Newsletter($featuredProducts));
37+
}
38+
39+
$this->info('Newsletter sent successfully.');
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Category;
6+
use App\Services\CategoryService;
7+
8+
class CategoryController extends Controller
9+
{
10+
/**
11+
* Display a listing of the resource.
12+
*/
13+
public function index()
14+
{
15+
$categories = CategoryService::getAll(request()->get('name'));
16+
17+
return $categories;
18+
}
19+
20+
/**
21+
* Display the specified resource.
22+
*/
23+
public function show(Category $category)
24+
{
25+
return $category;
26+
}
27+
28+
public function showBySlug($slug)
29+
{
30+
return Category::whereSlug($slug)
31+
->with('products')
32+
->firstOrFail();
33+
}
34+
}

app/Http/Controllers/Controller.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
abstract class Controller
6+
{
7+
//
8+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Product;
6+
use App\Services\ProductService;
7+
8+
class ProductController extends Controller
9+
{
10+
public function index()
11+
{
12+
$products = ProductService::getAll(request()->get('name'));
13+
14+
return $products;
15+
}
16+
17+
public function showBySlug($slug)
18+
{
19+
return Product::whereSlug($slug)->firstOrFail(); // Devuelve producto por slug
20+
}
21+
}

0 commit comments

Comments
 (0)