|
2 | 2 |
|
3 | 3 | namespace App\Http\Controllers; |
4 | 4 |
|
| 5 | +use App\Clients; |
| 6 | +use App\Haircuts; |
| 7 | +use App\Works; |
5 | 8 | use Illuminate\Http\Request; |
6 | 9 |
|
7 | 10 | class HomeController extends Controller |
8 | 11 | { |
9 | | - /** |
10 | | - * Create a new controller instance. |
11 | | - * |
12 | | - * @return void |
13 | | - */ |
14 | | - public function __construct() |
15 | | - { |
16 | | - $this->middleware('auth'); |
17 | | - } |
18 | | - |
19 | 12 | /** |
20 | 13 | * Show the application dashboard. |
21 | 14 | * |
22 | 15 | * @return \Illuminate\Contracts\Support\Renderable |
23 | 16 | */ |
24 | 17 | public function index() |
25 | 18 | { |
26 | | - return view('home'); |
| 19 | + return view('welcome', [ |
| 20 | + 'haircuts' => Haircuts::all()->toArray() ?? [], |
| 21 | + 'works' => Works::with('client')->with('haircut')->get()->toArray() ?? [], |
| 22 | + ]); |
| 23 | + } |
| 24 | + |
| 25 | + public function create() |
| 26 | + { |
| 27 | + $client = Clients::where([ |
| 28 | + ['first_name', request()->get('first_name')], |
| 29 | + ['second_name', request()->get('second_name')], |
| 30 | + ['third_name', request()->get('third_name')], |
| 31 | + ])->first(); |
| 32 | + |
| 33 | + if (!$client) { |
| 34 | + $client = Clients::create([ |
| 35 | + 'first_name' => request()->get('first_name'), |
| 36 | + 'second_name' => request()->get('second_name'), |
| 37 | + 'third_name' => request()->get('third_name'), |
| 38 | + ]); |
| 39 | + |
| 40 | + $client->save(); |
| 41 | + } |
| 42 | + |
| 43 | + $work = Works::create([ |
| 44 | + 'haircut_id' => request()->get('haircut_id'), |
| 45 | + 'client_id' => $client->id, |
| 46 | + ]); |
| 47 | + |
| 48 | + $work->save(); |
| 49 | + |
| 50 | + |
| 51 | + $count = Works::where('client_id', $client->id)->get()->count(); |
| 52 | + |
| 53 | + if ($count > 4) { |
| 54 | + $client->has_discount = true; |
| 55 | + |
| 56 | + $client->save(); |
| 57 | + } |
| 58 | + |
| 59 | + return redirect()->route('home'); |
27 | 60 | } |
28 | 61 | } |
0 commit comments