mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 12:34:06 +00:00
122 lines
4.4 KiB
PHP
122 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Company;
|
|
//use Image; //only used in companyProfile(), uncomment if using that portion of the code
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Validator;
|
|
|
|
class CompanyController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$input = $request->all();
|
|
Company::create($input);
|
|
return redirect('/');
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$company = Company::find($id);
|
|
if (!$company)
|
|
{
|
|
return response()->json(['message'=>'company not found'],200);
|
|
}
|
|
|
|
$company->company_name=$request->input('company_name');
|
|
$company->registration_no=$request->input('registration_no');
|
|
$company->tax_no=$request->input('tax_no');
|
|
$company->tel_no=$request->input('tel_no');
|
|
$company->fax=$request->input('fax');
|
|
$company->address=$request->input('address');
|
|
$company->city=$request->input('city');
|
|
$company->postcode=$request->input('postcode');
|
|
$company->state=$request->input('state');
|
|
$company->country=$request->input('country');
|
|
$company->contact_person=$request->input('contact_person');
|
|
|
|
$company->save();
|
|
return response()->json(['company'=>$company],200);
|
|
}
|
|
|
|
public function companyProfile(Request $request, $id)
|
|
{
|
|
$company = Company::find($id);//find the company first
|
|
if (!$company)
|
|
{
|
|
return response()->json(['message'=>'Document not found'],200);
|
|
}
|
|
//validaating file types
|
|
$validator = Validator::make($request->all(), [
|
|
'company_profile' => 'image|mimes:jpg,jpeg,bmp,png'
|
|
]);
|
|
if($validator->fails())
|
|
{
|
|
return "failed";
|
|
}
|
|
|
|
if($file = $request->file('company_profile')) //company profile picture
|
|
{
|
|
$company_profile = $request->file('company_profile');
|
|
$filename = $company_profile->getClientOriginalName(); //get the original file name
|
|
$unique_name = 'comp_prof_' . md5($filename. time()); //generating a random file name
|
|
|
|
$file = $request->file('company_profile');
|
|
$ext = $file->getClientOriginalExtension();
|
|
$input['company_profile'] = $filename;
|
|
Storage::putFileAs(
|
|
'company_profile',/*folder name*/ $file, $unique_name. '.' .$ext
|
|
);
|
|
$company->company_profile = $unique_name. '.' .$ext; //update database
|
|
// only use the following section of the code if you're omiting the upper portion, also uncomment the Image Library on line 7 & install Intervention Image package
|
|
/*
|
|
$name = $file->getClientOriginalName();
|
|
$img_file = $request->file('company_profile');
|
|
Image::make($img_file)->resize(300,300)->save(public_path('\company_profile'));
|
|
//return $img_file;
|
|
// $file->move('uploads/company_profile/', $img_file);
|
|
|
|
$input['company_profile'] = $name;
|
|
*/
|
|
} //end if
|
|
$company->save();
|
|
return response()->json(['company'=>$company],200);
|
|
}//end of companyProfile()
|
|
|
|
public function regCert(Request $request, $id)
|
|
{
|
|
$company = Company::find($id); //find the company first
|
|
if (!$company)
|
|
{
|
|
return response()->json(['message'=>'Document not found'],200);
|
|
}
|
|
|
|
//validating file types
|
|
$validator = Validator::make($request->all(), [
|
|
'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf'
|
|
]);
|
|
if($validator->fails()){
|
|
return "failed";
|
|
}
|
|
|
|
if($request->hasFile('reg_cert')) //Registration Certificate upload
|
|
{
|
|
$reg_cert = $request->file('reg_cert');
|
|
$filename = $reg_cert->getClientOriginalName(); //original filename
|
|
$unique_name = 'reg_cert_' . md5($filename. time()); //generating a random file name
|
|
|
|
$file = $request->file('reg_cert');
|
|
$ext = $file->getClientOriginalExtension();
|
|
$input['reg_cert'] = $filename;
|
|
Storage::putFileAs(
|
|
'reg_cert',/*folder name*/ $file, $unique_name. '.' .$ext
|
|
);
|
|
$company->reg_cert = $unique_name. '.' .$ext; //this updates database
|
|
}//end if
|
|
$company->save();
|
|
return response()->json(['company'=>$company],200);
|
|
}//end regCert()
|
|
|
|
}//end of class
|