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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace App\Http\Controllers;
use App\Company;
use App\User;
use App\Job;
use App\Applicant;
use Illuminate\Http\Request;
class CompanyController 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)
{
$imageCompany = null;
$imageMap = null;
if ($request->get('imageCompany') !== 'https://asianinteriorservices.com/wp-content/uploads/2018/04/noImg.png') {
$image = $request->get('imageCompany');
$name = 'Company'.time().'.'.explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
\Image::make($request->get('imageCompany'))->save(public_path('uploads/').$name);
$imageCompany = '/uploads/'.$name;
}
if ($request->get('imageMap')) {
$image = $request->get('imageMap');
$name = 'Map'.time().'.'.explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
\Image::make($request->get('imageMap'))->save(public_path('uploads/').$name);
$imageMap = '/uploads/'.$name;
}
$company = new Company();
$company->imageCompany = $imageCompany;
$company->company_name = $request->get('company_name');
$company->company_owner = $request->get('company_owner');
$company->phone_no = $request->get('phone_no');
$company->email = $request->get('email');
$company->fax = $request->get('fax');
$company->website = $request->get('website');
$company->addr = $request->get('addr');
$company->tambon = $request->get('tumbon');
$company->amphoe = $request->get('amphoe');
$company->province = $request->get('province');
$company->zipcode = $request->get('zip_code');
$company->imageMap = $imageMap;
$company->lat = $request->get('lat');
$company->long = $request->get('lng');
$company->about = $request->get('about');
$company->bts = $request->get('bts');
$company->mrt = $request->get('mrt');
$company->arl = $request->get('arl');
$company->bus = $request->get('bus');
$company->another = $request->get('another');
$company->user_id = $request->get('user_id');
$company->save();
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$exists = Company::where('user_id', $id)->exists();
$count = Job::where('user_id', $id)->count();
$acount = Applicant::join('jobs', 'applicants.job_id', 'jobs.id')->where('jobs.user_id', $id)->count();
if ($exists) {
return response()->json(['exists' => true, 'company' => Company::where('user_id', $id)->first(), 'count' => $count, 'acount' => $acount]);
} else {
return response()->json(['exists' => false, 'company' => User::where('id', $id)->first(), 'count' => $count, 'acount' => $acount]);
}
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$exists = Company::where('user_id', $id)->exists();
if ($exists) {
return response()->json(['exists' => true, 'company' => Company::where('user_id', $id)->first()]);
} else {
return response()->json(['exists' => false, 'company' => User::where('id', $id)->first()]);
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$company = Company::find($id);
if ($request->get('imageCompany') !== $company->imageCompany) {
if ($request->get('imageCompany') !== 'https://asianinteriorservices.com/wp-content/uploads/2018/04/noImg.png') {
$image = $request->get('imageCompany');
$name = 'Company'.time().'.'.explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
\Image::make($request->get('imageCompany'))->save(public_path('uploads/').$name);
$company->imageCompany = '/uploads/'.$name;
} else {
$company->imageCompany = 'https://asianinteriorservices.com/wp-content/uploads/2018/04/noImg.png';
}
}
if ($request->get('imageMap') !== $company->imageMap) {
if ($request->get('imageMap')) {
$image = $request->get('imageMap');
$name = 'Map'.time().'.'.explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
\Image::make($request->get('imageMap'))->save(public_path('uploads/').$name);
$company->imageMap = '/uploads/'.$name;;
} else {
$company->imageMap = null;
}
}
$company->company_name = $request->get('company_name');
$company->company_owner = $request->get('company_owner');
$company->phone_no = $request->get('phone_no');
$company->email = $request->get('email');
$company->fax = $request->get('fax');
$company->website = $request->get('website');
$company->addr = $request->get('addr');
$company->tambon = $request->get('tumbon');
$company->amphoe = $request->get('amphoe');
$company->province = $request->get('province');
$company->zipcode = $request->get('zip_code');
$company->lat = $request->get('lat');
$company->long = $request->get('lng');
$company->about = $request->get('about');
$company->bts = $request->get('bts');
$company->mrt = $request->get('mrt');
$company->arl = $request->get('arl');
$company->bus = $request->get('bus');
$company->another = $request->get('another');
$company->save();
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}