Company Profile has been completed and tested

This commit is contained in:
Aqeeb Imtiaz Harun
2018-05-16 09:57:03 +08:00
parent 3d1509d784
commit f72645e2c2
2 changed files with 70 additions and 67 deletions
+21 -30
View File
@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Company;
use Image;
//use Image; //only used in companyProfile(), uncomment if using that portion of the code
use Illuminate\Support\Facades\Storage;
use Validator;
@@ -24,13 +24,6 @@ class CompanyController extends Controller
return redirect('/');
}
/**
* 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);
@@ -57,16 +50,15 @@ class CompanyController extends Controller
public function companyProfile(Request $request, $id)
{
$company = Company::find($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";
@@ -75,10 +67,8 @@ class CompanyController extends Controller
if($file = $request->file('company_profile')) //company profile picture
{
$company_profile = $request->file('company_profile');
$filename = $company_profile->getClientOriginalName();
//$filename = $company_profile->uniqid('img_');
$unique_name = 'comp_prof_' . md5($filename);
//$destinationPath = config('app.fileDestinationPath').'/'.$filename;
$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();
@@ -86,14 +76,17 @@ class CompanyController extends Controller
Storage::putFileAs(
'company_profile',/*folder name*/ $file, $unique_name. '.' .$ext
);
$company->company_profile = $unique_name. '.' .$ext;
// $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);
$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;
$input['company_profile'] = $name;
*/
} //end if
$company->save();
return response()->json(['company'=>$company],200);
@@ -111,17 +104,15 @@ class CompanyController extends Controller
$validator = Validator::make($request->all(), [
'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf'
]);
if($validator->fails()){
return "failed";
}
if($validator->fails()){
return "failed";
}
if($request->hasFile('reg_cert')) //Registration Certificate upload
{
$reg_cert = $request->file('reg_cert');
$filename = $reg_cert->getClientOriginalName();
$unique_name = 'reg_cert_' . md5($filename);
//$destinationPath = config('app.fileDestinationPath').'/'.$filename;
$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();
@@ -129,7 +120,7 @@ class CompanyController extends Controller
Storage::putFileAs(
'reg_cert',/*folder name*/ $file, $unique_name. '.' .$ext
);
$company->reg_cert = $unique_name. '.' .$ext;
$company->reg_cert = $unique_name. '.' .$ext; //this updates database
}//end if
$company->save();
return response()->json(['company'=>$company],200);