diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 258f36c..83b71e6 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -4,17 +4,15 @@ namespace App\Http\Controllers; use App\Models\Product; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; class ProductController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ + public function index() { - // + // TMP do something better at some point maybe idk + return redirect()->route("product.create"); } /** @@ -24,7 +22,7 @@ class ProductController extends Controller */ public function create() { - // + return view("product/create"); } /** @@ -35,7 +33,18 @@ class ProductController extends Controller */ public function store(Request $request) { - // + Log::debug($request); + $request->validate([ + 'name'=>'required', + 'description'=>'required', + ]); + $product = new Product([ + 'name' => $request->get("name"), + 'description' => $request->get("description") + ]); + $product->save(); + //echo $product->uuid; + return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully"); } /** @@ -46,7 +55,7 @@ class ProductController extends Controller */ public function show(Product $product) { - // + return view("product/view", ["product" => $product]); } /** @@ -69,7 +78,9 @@ class ProductController extends Controller */ public function update(Request $request, Product $product) { - // + $product->fill($request->all()); + $product->save(); + return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully"); } /** @@ -80,6 +91,8 @@ class ProductController extends Controller */ public function destroy(Product $product) { - // + echo $product; + $product->delete(); + return redirect()->route("product.index"); } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 4f2529d..0fa9e87 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -8,13 +8,11 @@ use Illuminate\Database\Eloquent\Model; class Product extends Model { use HasFactory, HasUUID; + public $primaryKey = "uuid"; + protected $fillable = [ 'name', 'description', - 'password', ]; - - - } diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php index dd959c8..08c02e2 100644 --- a/database/factories/ProductFactory.php +++ b/database/factories/ProductFactory.php @@ -23,7 +23,7 @@ class ProductFactory extends Factory public function definition() { return [ - 'id' => $this->faker->unique()->uuid(), + 'uuid' => $this->faker->unique()->uuid(), 'name' => $this->faker->productName(), 'description' => $this->faker->text(10000), ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index dc3648d..13153a4 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -23,7 +23,7 @@ class UserFactory extends Factory public function definition() { return [ - 'id' => (string) Str::uuid(), + 'uuid' => (string) Str::uuid(), 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), diff --git a/database/migrations/2021_09_07_092431_create_products_table.php b/database/migrations/2021_09_07_092431_create_products_table.php index a54886b..e3218cd 100644 --- a/database/migrations/2021_09_07_092431_create_products_table.php +++ b/database/migrations/2021_09_07_092431_create_products_table.php @@ -14,7 +14,7 @@ class CreateProductsTable extends Migration public function up() { Schema::create('products', function (Blueprint $table) { - $table->uuid("id")->primary(); + $table->uuid("uuid")->primary()->unique(); $table->string("name", 255); $table->string("description", 10000); $table->timestamps(); diff --git a/docker-compose.yml b/docker-compose.yml index 420061f..37cee06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,7 @@ services: MYSQL_PASSWORD: '${DB_PASSWORD}' MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' volumes: - - 'sailmysql:/var/lib/mysql' + - './storage/mysql:/var/lib/mysql' networks: - sail healthcheck: diff --git a/resources/views/product/create.blade.php b/resources/views/product/create.blade.php new file mode 100644 index 0000000..c726071 --- /dev/null +++ b/resources/views/product/create.blade.php @@ -0,0 +1,25 @@ + + + + + + Document + + + +@if(Session::has('success')) +
+ {{Session::get('success')}} +
+@endif +
+
+ + + + @csrf +
+
+ + diff --git a/resources/views/product/view.blade.php b/resources/views/product/view.blade.php new file mode 100644 index 0000000..3da9375 --- /dev/null +++ b/resources/views/product/view.blade.php @@ -0,0 +1,22 @@ + + + + + + Document + + + +
+

+ {{ $product }} +

+
+ + @method('DELETE') + @csrf +
+
+ + diff --git a/routes/web.php b/routes/web.php index 7177c9f..994683b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name("login"); Route::post('/register', [LoginController::class, "register"])->name("register"); Route::any("/logout", [LoginController::class, "logout"])->name("logout"); + +Route::resource("product", ProductController::class);