Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
L
laravel_training
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
TTS Tran Viet Anh
laravel_training
Commits
a8178db3
Commit
a8178db3
authored
Nov 09, 2022
by
TTS Tran Viet Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve threads
parent
9dbf4827
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
72 deletions
+21
-72
HomeController.php
app/Http/Controllers/HomeController.php
+10
-71
Post.php
app/Models/Post.php
+5
-0
Product.php
app/Models/Product.php
+5
-0
index.blade.php
resources/views/client/index.blade.php
+1
-1
No files found.
app/Http/Controllers/HomeController.php
View file @
a8178db3
...
...
@@ -16,93 +16,32 @@ class HomeController extends Controller
*/
public
function
index
()
{
$productCategories
=
ProductCategory
::
query
()
->
get
();
$productCategories
=
ProductCategory
::
query
()
->
where
(
'parent_id'
,
'='
,
null
)
->
get
();
$latestDrops
=
Product
::
query
()
->
with
(
'productAttributes'
)
->
where
(
'status'
,
'='
,
Product
::
STATUS_ENABLE
)
->
statusEnabled
(
)
->
latest
()
->
take
(
4
)
->
get
();
$products
=
Product
::
query
()
->
take
(
8
)
->
get
();
$products
=
Product
::
query
()
->
latest
()
->
take
(
8
)
->
get
();
$latestBlogs
=
Post
::
query
()
->
with
(
'user'
)
->
statusPublished
()
->
latest
()
->
take
(
3
)
->
get
();
return
view
(
'client.index'
,
compact
(
'latestDrops'
,
'productCategories'
,
'products'
,
'latestBlogs'
));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public
function
create
()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public
function
store
(
Request
$request
)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
show
(
$id
)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
edit
(
$id
)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
update
(
Request
$request
,
$id
)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
destroy
(
$id
)
{
//
}
public
function
getProductsByCategory
(
Request
$request
)
{
$categoryID
=
$request
->
productCategoryID
;
$cats
=
ProductCategory
::
query
()
->
where
(
'id'
,
'='
,
$request
->
cat
)
->
orWhere
(
'parent_id'
,
'='
,
$request
->
cat
)
->
get
(
'id'
)
->
toArray
();
$productsByCategory
=
Product
::
query
()
->
where
(
'product_category_id'
,
'='
,
$categoryID
)
->
where
In
(
'product_category_id'
,
$cats
)
->
latest
()
->
take
(
8
)
->
get
();
...
...
app/Models/Post.php
View file @
a8178db3
...
...
@@ -26,4 +26,9 @@ public function user()
{
return
$this
->
belongsTo
(
User
::
class
);
}
public
function
scopeStatusPublished
(
$query
)
{
return
$query
->
where
(
'status'
,
'='
,
Post
::
STATUS_PUBLISHED
);
}
}
app/Models/Product.php
View file @
a8178db3
...
...
@@ -25,4 +25,9 @@ public function productAttributes()
{
return
$this
->
hasMany
(
ProductAttribute
::
class
);
}
public
function
scopeStatusEnabled
(
$query
)
{
return
$query
->
where
(
'status'
,
'='
,
Product
::
STATUS_ENABLED
);
}
}
resources/views/client/index.blade.php
View file @
a8178db3
...
...
@@ -107,7 +107,7 @@
type
:
"GET"
,
url
:
"{{ route('productsByCategory') }}"
,
data
:
{
productCategoryID
:
{{
$productCategory
->
id
}},
cat
:
{{
$productCategory
->
id
}},
},
success
:
function
(
data
)
{
$
(
'#productsByCategory'
)
.
html
(
data
);
...
...
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