Commit 0ac9ed16 authored by Artem's avatar Artem

improve product validation

parent 30366099
......@@ -150,7 +150,7 @@ class ProductController extends Controller
public function validateProduct()
{
return request()->validate([
'reference' => 'required',
'reference' => 'required|unique:products,reference',
'description_short' => 'required',
'description_long' => 'required',
'price' => 'required',
......
......@@ -15,10 +15,10 @@ class CreateProductsTable extends Migration
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('reference');
$table->string('reference')->unique();
$table->string('description_short');
$table->string('description_long');
$table->string('price');
$table->text('description_long');
$table->integer('price');
$table->string('type');
$table->timestamps();
});
......
......@@ -93,7 +93,7 @@
<div class="col-sm-10">
<input
type="text"
type="number"
class="form-control @error('price') is-invalid @enderror"
id="price"
name="price"
......
......@@ -42,7 +42,7 @@
<div class="form-group row">
<label for="price" class="col-sm-2 col-form-label">Price</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="price" name="price" value="{{ $product->price }}" required>
<input type="number" class="form-control" id="price" name="price" value="{{ $product->price }}" required>
</div>
</div>
<button class="btn btn-primary">Submit</button>
......
......@@ -3,8 +3,12 @@
@section('content')
<section class="product-info">
<div class="container">
<div>
<img src="/img/{{$product->type}}.jpg" alt="{{$product->reference}}">
</div>
<p>{{$product->reference}}</p>
<p>{{$product->description_short}}</p>
<p>{{$product->description_long}}</p>
<p>Price {{$product->price}} EUR</p>
<div>
<a {{--href="/product/{{ $product->id }}/edit"
href="{{ route('product.edit', $product) }}--}}
......
......@@ -15,17 +15,18 @@
<div class="product">
{{-- <a href="/product/{{$product->id}}" class="product__image">--}}
<a href="{{ $product->path() }}" class="product__image">
<img
@if ($product->type === 'Phone' || $product->type === 'Balalaika')
src="/img/{{$product->type}}.jpg"
@else
src="https://placehold.it/150x150"
@endif
alt="{{$product->reference}}">
<img src="/img/{{$product->type}}.jpg" alt="{{$product->reference}}">
{{-- <img--}}
{{-- @if ($product->type === 'Phone' || $product->type === 'Balalaika')--}}
{{-- src="/img/{{$product->type}}.jpg"--}}
{{-- @else--}}
{{-- src="https://placehold.it/150x150"--}}
{{-- @endif--}}
{{-- alt="{{$product->reference}}">--}}
</a>
<a href="{{ $product->path() }}" class="product__name">{{$product->reference}}</a>
<p class="product__short-text">{{$product->description_short}}</p>
<p class="product__price">{{$product->price}}</p>
<p class="product__price">{{$product->price}} EUR</p>
<button class="btn-add-to-basket">Add to basket</button>
</div>
</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment