Skip to content

Commit

Permalink
observers update
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorOlikov committed Apr 11, 2024
1 parent 6064bc8 commit ea633cf
Show file tree
Hide file tree
Showing 52 changed files with 505 additions and 339 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ yarn-error.log
#/docker/production
#vendor/laravel/framework/src/Illuminate/Http/Request.php
/docker/postgresql
/public/shop
/public/main-catalog
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function register(RegisterRequest $request)
'email' => $user->email,
'role_id' => 2,
'email_verified' => ($user->email_verified_at !== null),
'cart_id' => $user->cart_id,
],
], 201)->withCookie($cookie);
}
Expand Down Expand Up @@ -77,6 +78,7 @@ public function login(LoginRequest $request)
'email' => $user->email,
'role_id' => $user->role_id,
'email_verified' => ($user->email_verified_at !== null),
'cart_id' => $user->cart->id,
]
],200)->withCookie($cookie);
}
Expand Down
67 changes: 67 additions & 0 deletions app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\Image;
use App\Models\Product;
use Faker\Provider\Uuid;
use Illuminate\Http\Request;use Illuminate\Support\Str;

class CartController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$user = auth()->user();

//Image::insert([
// 'id' => Uuid::uuid(),
// 'imageable_type' => 'App\Models\Product',
// 'imageable_id' => '9bc20386-c3ff-410f-8927-fc0e65de6f48',
// 'url' => Str::random(10),
//]);

//$product = Product::first();

//$product->load('images');

$categories = Category::all();

return response($categories);
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
48 changes: 48 additions & 0 deletions app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class OrderController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/Product/CategoryProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function index(Request $request,Category $category)
$products = $category->products()->get();



return response($products,200);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cart extends Model

protected $table = 'carts';

protected $fillable = ['id','user_id'];
protected $fillable = ['id','user_id','status'];


public function user(): BelongsTo
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CartItem extends Model
use HasFactory, HasUuids;

protected $table = 'cart_items';
protected $fillable = ['cart_id','price','quantity'];
protected $fillable = ['cart_id','product_id','price','quantity'];

public function cart(): BelongsTo
{
Expand Down
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;



class User extends Authenticatable implements JWTSubject, MustVerifyEmail, CanResetPassword
{
use HasApiTokens, HasFactory, Notifiable, HasUuids, \Illuminate\Auth\Passwords\CanResetPassword;
Expand Down
50 changes: 49 additions & 1 deletion app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,55 @@

namespace App\Observers;

use App\Models\User;



class UserObserver
{
//
public function creating(User $user): void
{
//
}
/**
* Handle the Product "created" event.
*/
public function created(User $user): void
{
$cart = $user->cart()->create();

$user['cart_id'] = $cart->id;
}

/**
* Handle the Product "updated" event.
*/
public function updated(User $user): void
{
//
}

/**
* Handle the Product "deleted" event.
*/
public function deleted(User $user): void
{
//
}

/**
* Handle the Product "restored" event.
*/
public function restored(User $user): void
{
//
}

/**
* Handle the Product "force deleted" event.
*/
public function forceDeleted(User $user): void
{
//
}
}
10 changes: 9 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
namespace App\Providers;

use App\Contracts\JwtAuthServiceInterface;
use App\Models\Category;
use App\Models\Product;
use App\Models\User;
use App\Observers\CategoryObserver;
use App\Observers\ProductObserver;
use App\Observers\UserObserver;
use App\Services\JwtAuthService;
use Illuminate\Support\ServiceProvider;

Expand All @@ -21,6 +27,8 @@ public function register(): void
*/
public function boot(): void
{
//
User::observe(UserObserver::class);
Category::observe(CategoryObserver::class);
Product::observe(ProductObserver::class);
}
}
Loading

0 comments on commit ea633cf

Please sign in to comment.