Products
This commit is contained in:
parent
103fe77e74
commit
0e61588895
37 changed files with 778 additions and 61 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -14,3 +14,5 @@ yarn-error.log
|
||||||
/.idea
|
/.idea
|
||||||
/.vscode
|
/.vscode
|
||||||
.direnv
|
.direnv
|
||||||
|
.php_cs.cache
|
||||||
|
/storage/mysql
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Faker;
|
namespace App\Faker;
|
||||||
|
|
||||||
use Faker\Provider\Base;
|
use Faker\Provider\Base;
|
||||||
|
|
||||||
class ProductNameProvider extends Base
|
class ProductNameProvider extends Base
|
||||||
|
@ -89,4 +91,3 @@ class ProductNameProvider extends Base
|
||||||
return "$owner $adj $noun";
|
return "$owner $adj $noun";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
|
@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController;
|
||||||
|
|
||||||
class Controller extends BaseController
|
class Controller extends BaseController
|
||||||
{
|
{
|
||||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
use AuthorizesRequests;
|
||||||
|
use DispatchesJobs;
|
||||||
|
use ValidatesRequests;
|
||||||
}
|
}
|
||||||
|
|
54
app/Http/Controllers/ImageController.php
Normal file
54
app/Http/Controllers/ImageController.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Image;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class ImageController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return view("uploadImage");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$validatedData = $request->validate([
|
||||||
|
// The server should make sure to serve SVG files with the correct CSP to prevent XSS
|
||||||
|
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg,webp|max:5000',
|
||||||
|
]);
|
||||||
|
/*
|
||||||
|
Once the image is validated , create the name on the image
|
||||||
|
*/
|
||||||
|
$image = new Image();
|
||||||
|
|
||||||
|
$image->uuid = Str::uuid();
|
||||||
|
$image->path = $request->file('image')->store("uploads");
|
||||||
|
|
||||||
|
$image->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param \App\Models\Image $image
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(Image $image)
|
||||||
|
{
|
||||||
|
$image->delete();
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,12 +9,13 @@ use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
public function authenticate(Request $request) {
|
public function authenticate(Request $request)
|
||||||
|
{
|
||||||
$creds = $request->validate([
|
$creds = $request->validate([
|
||||||
'email' => ['required', 'email'],
|
'email' => ['required', 'email'],
|
||||||
'password' => ['required']
|
'password' => ['required']
|
||||||
]);
|
]);
|
||||||
if(Auth::attempt($creds)) {
|
if (Auth::attempt($creds)) {
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
return redirect()->intended();
|
return redirect()->intended();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +24,8 @@ class LoginController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(Request $request) {
|
public function register(Request $request)
|
||||||
|
{
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
$creds = $request->validate([
|
$creds = $request->validate([
|
||||||
|
@ -37,7 +39,8 @@ class LoginController extends Controller
|
||||||
return redirect("login")->withSuccess("Success! Now login");
|
return redirect("login")->withSuccess("Success! Now login");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout(Request $request) {
|
public function logout(Request $request)
|
||||||
|
{
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
$request->session()->invalidate();
|
$request->session()->invalidate();
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
|
@ -45,7 +48,8 @@ class LoginController extends Controller
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view() {
|
public function view()
|
||||||
|
{
|
||||||
return view("login", []);
|
return view("login", []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
114
app/Http/Controllers/OrderController.php
Normal file
114
app/Http/Controllers/OrderController.php
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Addres;
|
||||||
|
use App\Models\Order;
|
||||||
|
use App\Models\Product;
|
||||||
|
use Error;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
|
||||||
|
class OrderController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return view("order/create");
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
if (!$user) {
|
||||||
|
throw new AccessDeniedHttpException("Not logged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
$validated = $request->validate([
|
||||||
|
'products' => 'required|array',
|
||||||
|
'products.*' => 'exists:products,uuid'
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::transaction(function () use ($validated, $user) {
|
||||||
|
$products = array_map(fn ($v) => Product::query()->where("uuid", $v)->first(), $validated["products"]);
|
||||||
|
$order = new Order($products);
|
||||||
|
|
||||||
|
$order->user()->associate($user);
|
||||||
|
$order->cost = array_reduce($products,fn ($c, $i) => $c+=$i->price,0);
|
||||||
|
|
||||||
|
return $order->save();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show(Order $order)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function edit(Order $order)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function update(Request $request, Order $order)
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'address' => 'string',
|
||||||
|
]);
|
||||||
|
if(isset($validated["address"])) {
|
||||||
|
$address = $order->address()->withDefault(fn() => new Addres($validated));
|
||||||
|
$address->address = $validated["address"];
|
||||||
|
$order->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy(Order $order)
|
||||||
|
{
|
||||||
|
throw new Error("TODO");
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,6 @@ use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ProductController extends Controller
|
class ProductController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// TMP do something better at some point maybe idk
|
// TMP do something better at some point maybe idk
|
||||||
|
@ -91,7 +90,6 @@ class ProductController extends Controller
|
||||||
*/
|
*/
|
||||||
public function destroy(Product $product)
|
public function destroy(Product $product)
|
||||||
{
|
{
|
||||||
echo $product;
|
|
||||||
$product->delete();
|
$product->delete();
|
||||||
return redirect()->route("product.index");
|
return redirect()->route("product.index");
|
||||||
}
|
}
|
||||||
|
|
19
app/Http/Resources/order.php
Normal file
19
app/Http/Resources/order.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class order extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
15
app/Models/Addres.php
Normal file
15
app/Models/Addres.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Addres extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'address',
|
||||||
|
];
|
||||||
|
}
|
|
@ -11,8 +11,7 @@ use Illuminate\Support\Str;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
trait HasUUID
|
trait HasUUID
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static function getPrimaryKey()
|
protected static function getPrimaryKey()
|
||||||
{
|
{
|
||||||
return self::uuidField();
|
return self::uuidField();
|
||||||
|
@ -43,4 +42,4 @@ use Illuminate\Support\Str;
|
||||||
$model->{self::uuidField()} = (string) Str::uuid();
|
$model->{self::uuidField()} = (string) Str::uuid();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
app/Models/Image.php
Normal file
21
app/Models/Image.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class Image extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasUUID;
|
||||||
|
public $primaryKey = "uuid";
|
||||||
|
|
||||||
|
protected $fillable = [];
|
||||||
|
|
||||||
|
public function URL()
|
||||||
|
{
|
||||||
|
Storage::url($this->path);
|
||||||
|
}
|
||||||
|
}
|
28
app/Models/Order.php
Normal file
28
app/Models/Order.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Order extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasUUID;
|
||||||
|
public $primaryKey = "uuid";
|
||||||
|
protected $fillable = ['products'];
|
||||||
|
public function address()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Addres::class, "id", "addressId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, "userId", "uuid");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function products()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany("App\Product", "orderProduct","productId", "orderId");
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Product extends Model
|
class Product extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, HasUUID;
|
use HasFactory;
|
||||||
|
use HasUUID;
|
||||||
public $primaryKey = "uuid";
|
public $primaryKey = "uuid";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
class User extends Authenticatable {
|
class User extends Authenticatable
|
||||||
use HasApiTokens, HasFactory, HasUUID, Notifiable;
|
{
|
||||||
|
use HasApiTokens;
|
||||||
|
use HasFactory;
|
||||||
|
use HasUUID;
|
||||||
|
use Notifiable;
|
||||||
|
|
||||||
public $primaryKey = "uuid";
|
public $primaryKey = "uuid";
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,8 @@ namespace App\Providers;
|
||||||
use App\Faker\ProductNameProvider;
|
use App\Faker\ProductNameProvider;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
use Faker\{Factory, Generator};
|
use Faker\Factory;
|
||||||
|
use Faker\Generator;
|
||||||
|
|
||||||
class FakerServiceProvider extends ServiceProvider
|
class FakerServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
"guzzlehttp/guzzle": "^7.0.1",
|
"guzzlehttp/guzzle": "^7.0.1",
|
||||||
"laravel/framework": "^8.54",
|
"laravel/framework": "^8.54",
|
||||||
"laravel/sanctum": "^2.11",
|
"laravel/sanctum": "^2.11",
|
||||||
"laravel/tinker": "^2.5"
|
"laravel/tinker": "^2.5",
|
||||||
|
"php-decimal/laravel": "^1.1",
|
||||||
|
"php-decimal/php-decimal": "^1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"facade/ignition": "^2.5",
|
"facade/ignition": "^2.5",
|
||||||
|
|
179
composer.lock
generated
179
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "6cadd819a6415b190ae2704ced6e6c8b",
|
"content-hash": "844437f75eed2577e6c25d111a4ecd28",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "asm89/stack-cors",
|
"name": "asm89/stack-cors",
|
||||||
|
@ -1978,6 +1978,183 @@
|
||||||
},
|
},
|
||||||
"time": "2021-04-09T13:42:10+00:00"
|
"time": "2021-04-09T13:42:10+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "php-decimal/globals",
|
||||||
|
"version": "v1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-decimal/globals.git",
|
||||||
|
"reference": "589a296b471a3913ed41396d6fcae2a321788a78"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-decimal/globals/zipball/589a296b471a3913ed41396d6fcae2a321788a78",
|
||||||
|
"reference": "589a296b471a3913ed41396d6fcae2a321788a78",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.0.0",
|
||||||
|
"php-decimal/php-decimal": "^1.1.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"globals.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Rudi Theunissen",
|
||||||
|
"email": "rtheunissen@php.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Globals helpers for the decimal extension",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-decimal/globals/issues",
|
||||||
|
"source": "https://github.com/php-decimal/globals/tree/v1.1.0"
|
||||||
|
},
|
||||||
|
"time": "2018-11-20T21:18:50+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-decimal/laravel",
|
||||||
|
"version": "v1.1.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-decimal/laravel.git",
|
||||||
|
"reference": "fbc4137d40d1dfde1457ecc113dede57ac0de841"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-decimal/laravel/zipball/fbc4137d40d1dfde1457ecc113dede57ac0de841",
|
||||||
|
"reference": "fbc4137d40d1dfde1457ecc113dede57ac0de841",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.0.0",
|
||||||
|
"php-decimal/globals": "^1.1.0",
|
||||||
|
"php-decimal/php-decimal": "^1.1.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Decimal\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Rudi Theunissen",
|
||||||
|
"email": "rtheunissen@php.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Laravel integration package for decimal support",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-decimal/laravel/issues",
|
||||||
|
"source": "https://github.com/php-decimal/laravel/tree/v1.0.2"
|
||||||
|
},
|
||||||
|
"time": "2019-07-05T23:45:07+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-decimal/php-decimal",
|
||||||
|
"version": "v1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-decimal/php-decimal.git",
|
||||||
|
"reference": "ee8d92648fd06e82f9bfe0406d3670ebcddd946a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-decimal/php-decimal/zipball/ee8d92648fd06e82f9bfe0406d3670ebcddd946a",
|
||||||
|
"reference": "ee8d92648fd06e82f9bfe0406d3670ebcddd946a",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-decimal": "^1.1",
|
||||||
|
"php": ">=7.0.0",
|
||||||
|
"php-decimal/stubs": "^1.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Decimal\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Rudi Theunissen",
|
||||||
|
"email": "rtheunissen@php.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Correctly-rounded arbitrary precision decimal floating point",
|
||||||
|
"keywords": [
|
||||||
|
"decimal",
|
||||||
|
"math",
|
||||||
|
"number",
|
||||||
|
"precision"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-decimal/php-decimal/issues",
|
||||||
|
"source": "https://github.com/php-decimal/php-decimal/tree/v1.1.0"
|
||||||
|
},
|
||||||
|
"time": "2018-11-20T20:49:48+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-decimal/stubs",
|
||||||
|
"version": "v1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-decimal/stubs.git",
|
||||||
|
"reference": "168bb0d58bb398d7da739da0da99df2a9e1fc773"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-decimal/stubs/zipball/168bb0d58bb398d7da739da0da99df2a9e1fc773",
|
||||||
|
"reference": "168bb0d58bb398d7da739da0da99df2a9e1fc773",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.0.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Decimal\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Rudi Theunissen",
|
||||||
|
"email": "rtheunissen@php.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "IDE and static analysis helper for the decimal extension",
|
||||||
|
"keywords": [
|
||||||
|
"decimal",
|
||||||
|
"math",
|
||||||
|
"number",
|
||||||
|
"precision"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-decimal/stubs/issues",
|
||||||
|
"source": "https://github.com/php-decimal/stubs/tree/v1.1.0"
|
||||||
|
},
|
||||||
|
"time": "2018-11-20T20:48:40+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpoption/phpoption",
|
"name": "phpoption/phpoption",
|
||||||
"version": "1.8.0",
|
"version": "1.8.0",
|
||||||
|
|
|
@ -67,7 +67,7 @@ return [
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'links' => [
|
'links' => [
|
||||||
public_path('storage') => storage_path('app/public'),
|
public_path('storage') => storage_path('app'),
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
28
database/factories/OrderFactory.php
Normal file
28
database/factories/OrderFactory.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Order;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class OrderFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = Order::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ class ProductFactory extends Factory
|
||||||
return [
|
return [
|
||||||
'uuid' => $this->faker->unique()->uuid(),
|
'uuid' => $this->faker->unique()->uuid(),
|
||||||
'name' => $this->faker->productName(),
|
'name' => $this->faker->productName(),
|
||||||
|
'price' => $this->faker->numberBetween(1,32124),
|
||||||
'description' => $this->faker->text(10000),
|
'description' => $this->faker->text(10000),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ class CreateProductsTable extends Migration
|
||||||
$table->uuid("uuid")->primary()->unique();
|
$table->uuid("uuid")->primary()->unique();
|
||||||
$table->string("name", 255);
|
$table->string("name", 255);
|
||||||
$table->string("description", 10000);
|
$table->string("description", 10000);
|
||||||
|
$table->decimal("price");
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateImagesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('images', function (Blueprint $table) {
|
||||||
|
$table->uuid("uuid")->unique()->primary;
|
||||||
|
$table->string('path')->unique();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('images');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateOrdersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('addresses', function (Blueprint $table) {
|
||||||
|
$table->id('id');
|
||||||
|
$table->foreignUuid("userId")->references("uuid")->on("users");
|
||||||
|
|
||||||
|
// Address validation for international users is basically impossible so just use a string
|
||||||
|
$table->string("addres");
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('orders', function (Blueprint $table) {
|
||||||
|
$table->uuid("uuid")->unique()->primary();
|
||||||
|
$table->boolean("fulfilled")->default(false);
|
||||||
|
|
||||||
|
$table->foreignUuid("userId")->references("uuid")->on("users");
|
||||||
|
$table->foreignId("addressId")->nullable()->references("id")->on("addresses");
|
||||||
|
|
||||||
|
$table->decimal("cost");
|
||||||
|
$table->boolean("paid")->default(false);
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create("orderProduct", function (Blueprint $table) {
|
||||||
|
$table->foreignUuid("productId")->references("uuid")->on("products")->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
|
$table->foreignUuid("orderId")->references("uuid")->on("orders")->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('orderProduct');
|
||||||
|
Schema::dropIfExists('orders');
|
||||||
|
Schema::dropIfExists('addresses');
|
||||||
|
}
|
||||||
|
}
|
18
database/seeders/OrderSeeder.php
Normal file
18
database/seeders/OrderSeeder.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class OrderSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ version: '3'
|
||||||
services:
|
services:
|
||||||
laravel.test:
|
laravel.test:
|
||||||
build:
|
build:
|
||||||
context: ./vendor/laravel/sail/runtimes/8.0
|
context: ./docker/8.0
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
args:
|
args:
|
||||||
WWWGROUP: '${WWWGROUP}'
|
WWWGROUP: '${WWWGROUP}'
|
||||||
|
@ -24,7 +24,7 @@ services:
|
||||||
depends_on:
|
depends_on:
|
||||||
- mysql
|
- mysql
|
||||||
mysql:
|
mysql:
|
||||||
image: 'mysql:8.0'
|
image: 'mariadb:10'
|
||||||
ports:
|
ports:
|
||||||
- '${FORWARD_DB_PORT:-3306}:3306'
|
- '${FORWARD_DB_PORT:-3306}:3306'
|
||||||
environment:
|
environment:
|
||||||
|
|
57
docker/8.0/Dockerfile
Normal file
57
docker/8.0/Dockerfile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
FROM ubuntu:21.04
|
||||||
|
|
||||||
|
LABEL maintainer="Taylor Otwell"
|
||||||
|
|
||||||
|
ARG WWWGROUP
|
||||||
|
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
ENV TZ=UTC
|
||||||
|
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
|
||||||
|
&& mkdir -p ~/.gnupg \
|
||||||
|
&& chmod 600 ~/.gnupg \
|
||||||
|
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
|
||||||
|
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
|
||||||
|
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
|
||||||
|
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get install -y php8.0-cli php8.0-dev \
|
||||||
|
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
|
||||||
|
php8.0-curl php8.0-memcached \
|
||||||
|
php8.0-imap php8.0-mysql php8.0-mbstring \
|
||||||
|
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
|
||||||
|
php8.0-intl php8.0-readline php8.0-pcov \
|
||||||
|
php8.0-msgpack php8.0-igbinary php8.0-ldap \
|
||||||
|
php8.0-redis php8.0-swoole php8.0-xdebug \
|
||||||
|
php-decimal \
|
||||||
|
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
|
||||||
|
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
|
||||||
|
&& apt-get install -y nodejs \
|
||||||
|
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
|
||||||
|
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get install -y yarn \
|
||||||
|
&& apt-get install -y mysql-client \
|
||||||
|
&& apt-get install -y postgresql-client \
|
||||||
|
&& apt-get -y autoremove \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
|
||||||
|
|
||||||
|
RUN groupadd --force -g $WWWGROUP sail
|
||||||
|
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
|
||||||
|
|
||||||
|
COPY start-container /usr/local/bin/start-container
|
||||||
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
|
||||||
|
RUN chmod +x /usr/local/bin/start-container
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
ENTRYPOINT ["start-container"]
|
4
docker/8.0/php.ini
Normal file
4
docker/8.0/php.ini
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[PHP]
|
||||||
|
post_max_size = 100M
|
||||||
|
upload_max_filesize = 100M
|
||||||
|
variables_order = EGPCS
|
17
docker/8.0/start-container
Normal file
17
docker/8.0/start-container
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ ! -z "$WWWUSER" ]; then
|
||||||
|
usermod -u $WWWUSER sail
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d /.composer ]; then
|
||||||
|
mkdir /.composer
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod -R ugo+rw /.composer
|
||||||
|
|
||||||
|
if [ $# -gt 0 ];then
|
||||||
|
exec gosu $WWWUSER "$@"
|
||||||
|
else
|
||||||
|
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
fi
|
14
docker/8.0/supervisord.conf
Normal file
14
docker/8.0/supervisord.conf
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
user=root
|
||||||
|
logfile=/var/log/supervisor/supervisord.log
|
||||||
|
pidfile=/var/run/supervisord.pid
|
||||||
|
|
||||||
|
[program:php]
|
||||||
|
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
|
||||||
|
user=sail
|
||||||
|
environment=LARAVEL_SAIL="1"
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
24
resources/views/order/create.blade.php
Normal file
24
resources/views/order/create.blade.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
@if(Session::has('success'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{Session::get('success')}}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div>
|
||||||
|
<form method="post" action="./">
|
||||||
|
<input type="text" name="products[0]">
|
||||||
|
<input type="submit">
|
||||||
|
@csrf
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
resources/views/uploadImage.blade.php
Normal file
24
resources/views/uploadImage.blade.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
@if(Session::has('success'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{Session::get('success')}}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div>
|
||||||
|
<form method="post" action="{{ route("image.store") }}" enctype="multipart/form-data">
|
||||||
|
<input type="file" name="image">
|
||||||
|
<input type="submit">
|
||||||
|
@csrf
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -18,4 +18,3 @@ use Illuminate\Support\Facades\Artisan;
|
||||||
Artisan::command('inspire', function () {
|
Artisan::command('inspire', function () {
|
||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
})->purpose('Display an inspiring quote');
|
})->purpose('Display an inspiring quote');
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\ImageController;
|
||||||
use App\Http\Controllers\LoginController;
|
use App\Http\Controllers\LoginController;
|
||||||
|
use App\Http\Controllers\OrderController;
|
||||||
use App\Http\Controllers\ProductController;
|
use App\Http\Controllers\ProductController;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
@ -32,3 +34,5 @@ Route::post('/register', [LoginController::class, "register"])->name("register")
|
||||||
Route::any("/logout", [LoginController::class, "logout"])->name("logout");
|
Route::any("/logout", [LoginController::class, "logout"])->name("logout");
|
||||||
|
|
||||||
Route::resource("product", ProductController::class);
|
Route::resource("product", ProductController::class);
|
||||||
|
Route::resource("order", OrderController::class);
|
||||||
|
Route::resource("image", ImageController::class)->only(["store", "delete", "create"]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{ pkgs ? import <nixpkgs> { } }:
|
{ pkgs ? import <nixpkgs> { } }:
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
# nativeBuildInputs is usually what you want -- tools you need to run
|
# nativeBuildInputs is usually what you want -- tools you need to run
|
||||||
nativeBuildInputs = with pkgs; [ php80Packages.composer php80 yarn docker-compose docker];
|
nativeBuildInputs = with pkgs; [ php80Packages.php-cs-fixer php80Packages.composer php80 yarn docker-compose docker];
|
||||||
}
|
}
|
||||||
|
|
2
storage/mysql/.gitignore
vendored
2
storage/mysql/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
*
|
|
||||||
!.gitignore
|
|
|
@ -15,6 +15,5 @@ class RegistrationTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->post("/register", ["email" => "a@a.com", "username" => "aaa", "password" => "password"])->assertRedirect();
|
$this->post("/register", ["email" => "a@a.com", "username" => "aaa", "password" => "password"])->assertRedirect();
|
||||||
$this->post("/login", ["email" => "a@a.com", "username" => "aaa", "password" => "password"])->assertRedirect("/");
|
$this->post("/login", ["email" => "a@a.com", "username" => "aaa", "password" => "password"])->assertRedirect("/");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue