Skip to content

Commit

Permalink
Posting Product: complete && Multiple category: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Slymee committed Jan 18, 2024
1 parent 819e6e4 commit 3a8f398
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions app/Http/Controllers/ProductAdController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,25 @@ public function create()
*/
public function store(CreateProductAdRequest $request)
{
$selectedCategories = $request->all('categories');
dd($selectedCategories);
try{
$imageName = 'solo' . time() . 'leveling' .'.'. $request->product_image->extension();

if($imagePath = $request->file('product_image')->storeAs('images', $imageName)){
ProductAd::create([
'user_id' => $request->input('user_id'),
'product_title' => $request->input('product_title'),
'product_description' => $request->input('product_description'),
'product_price' => $request->input('product_price'),
'product_tag' => $request->input('product_tag'),
'image_path' => $imagePath,
]);
return redirect()->back()->with('message', 'Product Added.');
}
return redirect()->back()->with('message', 'Product Add Failed.');

}catch(\Exception $e){
return redirect()->back()->with('message', $e->getMessage());
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Models/ProductAd.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProductAd extends Model
'user_id',
'product_title',
'product_description',
'product_price',
'product_tag',
'image_path',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up(): void
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('product_title');
$table->text('product_description');
$table->decimal('product_price', 10, 2);
$table->decimal('product_price', 10, 2)->default('0');
$table->string('product_tag');
$table->string('image_path')->nullable();
$table->timestamps();
Expand Down

0 comments on commit 3a8f398

Please sign in to comment.