Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
test-webshop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Artem
test-webshop
Commits
6939c207
Commit
6939c207
authored
May 04, 2020
by
ArtemTropanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
impelement named routes for show and edit methods
parent
27e1efbd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
6 deletions
+19
-6
ProductController.php
app/Http/Controllers/ProductController.php
+1
-1
Product.php
app/Product.php
+10
-0
product.blade.php
resources/views/product/product.blade.php
+3
-1
welcome.blade.php
resources/views/welcome.blade.php
+3
-2
web.php
routes/web.php
+2
-2
No files found.
app/Http/Controllers/ProductController.php
View file @
6939c207
...
...
@@ -132,7 +132,7 @@ class ProductController extends Controller
$product
->
update
(
$this
->
validateProduct
());
return
redirect
(
"/product/
{
$product
->
id
}
"
);
return
redirect
(
$product
->
path
()
);
}
/**
...
...
app/Product.php
View file @
6939c207
...
...
@@ -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
);
}
}
resources/views/product/product.blade.php
View file @
6939c207
...
...
@@ -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
resources/views/welcome.blade.php
View file @
6939c207
...
...
@@ -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>
...
...
routes/web.php
View file @
6939c207
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment