Commit 6939c207 authored by ArtemTropanets's avatar ArtemTropanets

impelement named routes for show and edit methods

parent 27e1efbd
......@@ -132,7 +132,7 @@ class ProductController extends Controller
$product->update($this->validateProduct());
return redirect("/product/{$product->id}");
return redirect($product->path());
}
/**
......
......@@ -8,4 +8,14 @@ class Product extends Model
{
protected $fillable = ['reference', 'description_short', 'description_long', 'type', 'price'];
// protected $guarded = []; //remove protection against mass assignment
public function path()
{
return route('product.show', $this); // this is $product
}
public function editPath()
{
return route('product.edit', $this);
}
}
......@@ -5,7 +5,9 @@
<div class="container">
<p>{{$product->reference}}</p>
<p>{{$product->description_short}}</p>
<div><a href="/product/{{ $product->id }}/edit">Edit product</a></div>
{{-- <div><a href="/product/{{ $product->id }}/edit">Edit product</a></div>--}}
{{-- <div><a href="{{ route('product.edit', $product) }}">Edit product</a></div>--}}
<div><a href="{{ $product->editPath() }}">Edit product</a></div>
</div>
</section>
@endsection
......@@ -13,7 +13,8 @@
@foreach($products as $product)
<li class="product-list__item">
<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">
<img
@if ($product->type === 'Phone' || $product->type === 'Balalaika')
src="/img/{{$product->type}}.jpg"
......@@ -22,7 +23,7 @@
@endif
alt="{{$product->reference}}">
</a>
<a href="/product/{{$product->id}}" 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__price">{{$product->price}}</p>
<button class="btn-add-to-basket">Add to basket</button>
......
......@@ -16,8 +16,8 @@ use Illuminate\Support\Facades\Route;
Route::get('/', 'ProductController@index');
Route::post('/product', 'ProductController@store');
Route::get('/product/create', 'ProductController@create');
Route::get('/product/{product}', 'ProductController@show');
Route::get('/product/{product}/edit', 'ProductController@edit');
Route::get('/product/{product}', 'ProductController@show')->name('product.show');
Route::get('/product/{product}/edit', 'ProductController@edit')->name('product.edit');
Route::put('/product/{product}', 'ProductController@update');
Auth::routes();
......
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