Blame view

app/Http/Controllers/Admin/CompanyAreaController.php 4.13 KB
3575d19ae   Андрей Ларионов   Админка новости и...
1
2
3
4
5
6
  <?php
  
  namespace App\Http\Controllers\Admin;
  
  use App\Http\Controllers\Controller;
  use App\Models\Contact;
d82a28f22   Андрей Ларионов   Админка форматы и...
7
  use App\Models\Partners;
3575d19ae   Андрей Ларионов   Админка новости и...
8
  use Illuminate\Http\Request;
d82a28f22   Андрей Ларионов   Админка форматы и...
9
10
  use Illuminate\Support\Facades\Session;
  use Illuminate\Support\Facades\Storage;
3575d19ae   Андрей Ларионов   Админка новости и...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  use Illuminate\Support\Facades\Validator;
  
  class CompanyAreaController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          //
      }
  
      /**
       * 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  \App\Models\Contact  $contact
       * @return \Illuminate\Http\Response
       */
      public function show(Contact $contact)
      {
          $firm_data = Contact::find(1);
d82a28f22   Андрей Ларионов   Админка форматы и...
55
56
          $partners = Partners::query()->get();
          return view('admin.company.view', compact('firm_data', 'partners'));
3575d19ae   Андрей Ларионов   Админка новости и...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
      }
  
      /**
       * Show the form for editing the specified resource.
       *
       * @param  \App\Models\Contact  $contact
       * @return \Illuminate\Http\Response
       */
      public function edit(Contact $contact)
      {
          $firm_data = Contact::find(1);
          return view('admin.company.edit', compact('firm_data'));
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \App\Models\Contact  $contact
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, Contact $contact)
      {
          $rules = [
              'email' => 'required|min:3|max:255',
              'telephone' => 'required|min:3|max:255',
          ];
          $messages = [
              'required' => 'Укажите обязательное поле',
          ];
  
          $validator = Validator::make($request->all(), $rules, $messages);
  
          if ($validator->fails()) {
              return redirect()->route('admin.company.edit', ['company' => 1])
                  ->withErrors($validator);
          } else {
              $params = $request->all();
ad1c26f2f   Андрей Ларионов   Админка - контакт...
95
96
              $company = Contact::find(1);
              $company->update($params);
3575d19ae   Андрей Ларионов   Админка новости и...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
              return redirect()->route('admin.company.show', ['company' => 1]);
          }
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  \App\Models\Contact  $contact
       * @return \Illuminate\Http\Response
       */
      public function destroy(Contact $contact)
      {
          //
      }
d82a28f22   Андрей Ларионов   Админка форматы и...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  
      /**
       * Добавление партнера
       */
      public function add_partner() {
          return view('admin.company.add_partner');
      }
  
      /**
       * Сохранение нового партнера
       */
      public function add_partner_post(Request $request) {
          $rules = [
              'name' => 'required|min:3|max:255',
              'foto' => 'required|min:3|max:255',
          ];
          $messages = [
              'required' => 'Укажите обязательное поле',
          ];
  
          $validator = Validator::make($request->all(), $rules, $messages);
  
          if ($validator->fails()) {
              return redirect()->route('admin.add.partner')
                  ->withErrors($validator);
          } else {
              //$params = $request->all();
              $partner = new Partners();
              $partner->name = $request->name;
              $partner->foto =  $request->file('foto')->store('partners', 'public');
              $partner->save();
  
              return redirect()->route('admin.company.show', ['company' => 1]);
          }
      }
  
      /**
       * Удаление партнера
       */
      public function delete_partner(Partners $partner) {
          Storage::delete($partner->foto);
          $partner->delete();
          Session::flash('message','Партнер был успешно удален!');
  
          return redirect()->route('admin.company.show', ['company' => 1]);
      }
3575d19ae   Андрей Ларионов   Админка новости и...
157
  }