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
94b0a557
Commit
94b0a557
authored
May 08, 2020
by
Artem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add store order module
parent
0bfb296e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
2 deletions
+116
-2
Cart.php
app/Cart.php
+0
-1
OrderController.php
app/Http/Controllers/OrderController.php
+32
-0
Order.php
app/Order.php
+15
-0
2020_05_07_165508_create_orders_table.php
...base/migrations/2020_05_07_165508_create_orders_table.php
+39
-0
UserSeeder.php
database/seeds/UserSeeder.php
+23
-0
cart.blade.php
resources/views/cart.blade.php
+5
-1
web.php
routes/web.php
+2
-0
No files found.
app/Cart.php
View file @
94b0a557
...
...
@@ -4,7 +4,6 @@ namespace App;
//use Illuminate\Database\Eloquent\Model;
use
App\Product
;
use
DB
;
class
Cart
/*extends Model*/
{
...
...
app/Http/Controllers/OrderController.php
0 → 100644
View file @
94b0a557
<?php
namespace
App\Http\Controllers
;
use
App\Order
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Auth
;
use
Session
;
class
OrderController
extends
Controller
{
function
store
()
{
if
(
!
Session
::
has
(
'cart'
))
{
return
redirect
(
'cart'
);
}
$cart
=
Session
::
get
(
'cart'
);
$order
=
Order
::
create
([
'user_id'
=>
Auth
::
id
(),
'total_price'
=>
$cart
->
total_price
,
'total_qty'
=>
$cart
->
total_qty
,
]);
$order_id
=
$order
->
id
;
Session
::
forget
(
'cart'
);
return
view
(
'cart'
,
compact
(
'order_id'
));
}
}
app/Order.php
0 → 100644
View file @
94b0a557
<?php
namespace
App
;
use
Illuminate\Database\Eloquent\Model
;
class
Order
extends
Model
{
protected
$fillable
=
[
'user_id'
,
'total_price'
,
'total_qty'
];
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
);
}
}
database/migrations/2020_05_07_165508_create_orders_table.php
0 → 100644
View file @
94b0a557
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateOrdersTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'orders'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
unsignedBigInteger
(
'user_id'
);
$table
->
string
(
'total_price'
);
$table
->
string
(
'total_qty'
);
$table
->
timestamps
();
$table
->
foreign
(
'user_id'
)
->
references
(
'id'
)
->
on
(
'users'
)
->
onDelete
(
'cascade'
);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'orders'
);
}
}
database/seeds/UserSeeder.php
0 → 100644
View file @
94b0a557
<?php
use
Illuminate\Database\Seeder
;
use
App\User
;
class
UserSeeder
extends
Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public
function
run
()
{
User
::
create
([
'name'
=>
'Artem'
,
'email'
=>
'ololo@info.com'
,
'email_verified_at'
=>
now
(),
'password'
=>
'123123123'
,
'remember_token'
=>
Str
::
random
(
10
),
]);
}
}
resources/views/cart.blade.php
View file @
94b0a557
...
...
@@ -72,7 +72,11 @@
</table>
@else
<div>There are no products in the cart. <a href="
{{
route
(
'homepage'
)
}}
">Check our products</a></div>
@if(isset(
$order_id
))
<div class="
alert
alert
-
success
">Thank you, order succesfully placed. Your order number is <b>{{
$order_id
}}</b>. We will contact you shortly.</div>
@else
<div>There are no products in the cart. <a href="
{{
route
(
'homepage'
)
}}
">Check our products</a></div>
@endif
@endif
</div>
...
...
routes/web.php
View file @
94b0a557
...
...
@@ -36,5 +36,7 @@ Route::prefix('cart')->group(function() {
Route
::
post
(
'/remove/{product}'
,
'CartController@removeFromCart'
)
->
name
(
'cart.removeFromCart'
);
Route
::
post
(
'/clear'
,
'CartController@clearCart'
)
->
name
(
'cart.clearCart'
);
});
//
Route
::
redirect
(
'order'
,
'/'
);
// TODO to ask if there is a way to show 404 and not use redirect
Route
::
post
(
'order'
,
'OrderController@store'
)
->
name
(
'order.sendOrder'
)
->
middleware
(
'auth'
);
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