Commit 0ac9ed16 authored by Artem's avatar Artem

improve product validation

parent 30366099
...@@ -150,7 +150,7 @@ class ProductController extends Controller ...@@ -150,7 +150,7 @@ class ProductController extends Controller
public function validateProduct() public function validateProduct()
{ {
return request()->validate([ return request()->validate([
'reference' => 'required', 'reference' => 'required|unique:products,reference',
'description_short' => 'required', 'description_short' => 'required',
'description_long' => 'required', 'description_long' => 'required',
'price' => 'required', 'price' => 'required',
......
...@@ -15,10 +15,10 @@ class CreateProductsTable extends Migration ...@@ -15,10 +15,10 @@ class CreateProductsTable extends Migration
{ {
Schema::create('products', function (Blueprint $table) { Schema::create('products', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('reference'); $table->string('reference')->unique();
$table->string('description_short'); $table->string('description_short');
$table->string('description_long'); $table->text('description_long');
$table->string('price'); $table->integer('price');
$table->string('type'); $table->string('type');
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input <input
type="text" type="number"
class="form-control @error('price') is-invalid @enderror" class="form-control @error('price') is-invalid @enderror"
id="price" id="price"
name="price" name="price"
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="price" class="col-sm-2 col-form-label">Price</label> <label for="price" class="col-sm-2 col-form-label">Price</label>
<div class="col-sm-10"> <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>
</div> </div>
<button class="btn btn-primary">Submit</button> <button class="btn btn-primary">Submit</button>
......
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
@section('content') @section('content')
<section class="product-info"> <section class="product-info">
<div class="container"> <div class="container">
<div>
<img src="/img/{{$product->type}}.jpg" alt="{{$product->reference}}">
</div>
<p>{{$product->reference}}</p> <p>{{$product->reference}}</p>
<p>{{$product->description_short}}</p> <p>{{$product->description_long}}</p>
<p>Price {{$product->price}} EUR</p>
<div> <div>
<a {{--href="/product/{{ $product->id }}/edit" <a {{--href="/product/{{ $product->id }}/edit"
href="{{ route('product.edit', $product) }}--}} href="{{ route('product.edit', $product) }}--}}
......
...@@ -15,17 +15,18 @@ ...@@ -15,17 +15,18 @@
<div class="product"> <div class="product">
{{-- <a href="/product/{{$product->id}}" class="product__image">--}} {{-- <a href="/product/{{$product->id}}" class="product__image">--}}
<a href="{{ $product->path() }}" class="product__image"> <a href="{{ $product->path() }}" class="product__image">
<img <img src="/img/{{$product->type}}.jpg" alt="{{$product->reference}}">
@if ($product->type === 'Phone' || $product->type === 'Balalaika') {{-- <img--}}
src="/img/{{$product->type}}.jpg" {{-- @if ($product->type === 'Phone' || $product->type === 'Balalaika')--}}
@else {{-- src="/img/{{$product->type}}.jpg"--}}
src="https://placehold.it/150x150" {{-- @else--}}
@endif {{-- src="https://placehold.it/150x150"--}}
alt="{{$product->reference}}"> {{-- @endif--}}
{{-- alt="{{$product->reference}}">--}}
</a> </a>
<a href="{{ $product->path() }}" class="product__name">{{$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__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> <button class="btn-add-to-basket">Add to basket</button>
</div> </div>
</li> </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