-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderController.php
More file actions
31 lines (25 loc) · 861 Bytes
/
OrderController.php
File metadata and controls
31 lines (25 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Order;
use App\Models\Customer;
class OrderController extends Controller
{
public function index()
{
return view('welcome', ['orders' => Order::all()], ['customers' => Customer::all()]);
}
public function saveOrder(Request $request)
{
$newOrder = new Order;
$newOrder->customer_id = $request->customer_id;
$newOrder->customer_name = $request->customer_name;
$newOrder->delivery_date = $request->delivery_date;
$newOrder->freight_value = $request->freight_value;
if ($newOrder->save()) {
return redirect('/')->with('success', 'Pedido criado com sucesso!');
} else {
return redirect('/')->with('error', 'Ocorreu um erro ao tentar criar o pedido.');
}
}
}