added file upload for both company profile picture and registration certificate

This commit is contained in:
Aqeeb Imtiaz Harun
2018-05-07 11:11:57 +08:00
parent 6c5e0b6e0e
commit 2da890f36e
9 changed files with 85 additions and 19 deletions
+1 -1
View File
@@ -7,6 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class Company extends Model class Company extends Model
{ {
// //
protected $fillable = ['company_profile', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; protected $fillable = ['company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person'];
//protected $guarded = []; //protected $guarded = [];
} }
+80 -13
View File
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Company; use App\Company;
use Image; use Image;
use Illuminate\Support\Facades\Storage;
class CompanyController extends Controller class CompanyController extends Controller
{ {
@@ -50,21 +51,65 @@ class CompanyController extends Controller
// return response()->json(['message'=>'Document not found']); // return response()->json(['message'=>'Document not found']);
// } // }
$input = $request->all(); $input = $request->all();
if($file = $request->file('company_profile'))
//validating uploaded files
// $this->validate(request(),[
// 'company_profile' => 'required|image|mimes:jpg,jpeg,bmp,png',
// 'reg_cerf' => 'required|mimes:jpg,jpeg,bmp,png,gif,svg,pdf'
// ]);
if($file = $request->file('company_profile')) //company profile picture
{ {
$name = $file->getClientOriginalName(); $company_profile = $request->file('company_profile');
$img_file = $request->file('company_profile'); $filename = $company_profile->getClientOriginalName();
//$destinationPath = config('app.fileDestinationPath').'/'.$filename;
Image::make($img_file)->resize(300,300)->save(public_path('uploads\company_profile\hello.jpg')); $file = $request->file('company_profile');
return $img_file; $ext = $file->getClientOriginalExtension();
// $file->move('uploads/company_profile/', $img_file);
$input['company_profile'] = $name; Storage::putFileAs(
'company_profile',/*folder name*/ $file, $filename. '.' .$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);
// $input['company_profile'] = $name;
} }
if($request->hasFile('reg_cert')) //Registration Certificate upload
{
$reg_cert = $request->file('reg_cert');
$filename = $reg_cert->getClientOriginalName();
//$destinationPath = config('app.fileDestinationPath').'/'.$filename;
$file = $request->file('reg_cert');
$ext = $file->getClientOriginalExtension();
Storage::putFileAs(
'reg_cert',/*folder name*/ $file, $filename. '.' .$ext
);
// $uploaded = Storage::put($destinationPath, file_get_contents($reg_cert->getRealPath()));
// $name = $file->getClientOriginalName();
// $img_file = $request->file('reg_cert');
// Image::make($img_file)->save(public_path('uploads\reg_cert'));
// $input['company_profile'] = $name;
// $request->file('req_cert');
// //$request->image->store('\uploads\reg_cert');
// Storage::putFile('uploads\reg_cert', $request->file('reg_cert'));
}
// else{
// return "failed";
// }
Company::create($input); Company::create($input);
//Company::create(request()->all()); //Company::create(request()->all());
//dd(request()->all()); //dd(request()->all());
// return redirect('/'); return redirect('/');
} }
/** /**
@@ -103,12 +148,34 @@ class CompanyController extends Controller
{ {
return response()->json(['message'=>'Document not found'],200); return response()->json(['message'=>'Document not found'],200);
} }
//$warehouse->address='juhgfd'; //updating company profile picture
if($request->hasFile('avatar')) if($file = $request->file('company_profile')) //company profile picture
{ {
$avatar = $request->file('avatar'); $company_profile = $request->file('company_profile');
$filename = time() . '.' . $avatar->getClientOriginalExtension(); $filename = $company_profile->getClientOriginalName();
Image::make($avatar)->resize(300,300)->save(public_path('/uploads/company_profile/'.$filename)); //$destinationPath = config('app.fileDestinationPath').'/'.$filename;
$file = $request->file('company_profile');
$ext = $file->getClientOriginalExtension();
Storage::putFileAs(
'company_profile',/*folder name*/ $file, $filename. '.' .$ext
);
}
//updating registration certificate
if($request->hasFile('reg_cert')) //Registration Certificate upload
{
$reg_cert = $request->file('reg_cert');
$filename = $reg_cert->getClientOriginalName();
//$destinationPath = config('app.fileDestinationPath').'/'.$filename;
$file = $request->file('reg_cert');
$ext = $file->getClientOriginalExtension();
Storage::putFileAs(
'reg_cert',/*folder name*/ $file, $filename. '.' .$ext
);
} }
$company->company_name=$request->input('company_name'); $company->company_name=$request->input('company_name');
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
return [ return [
//'fileDestinationPath' => 'uploads',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Application Name | Application Name
@@ -16,6 +16,7 @@ class CreateCompaniesTable extends Migration
Schema::create('companies', function (Blueprint $table) { Schema::create('companies', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('company_profile');//->default('default.jpg'); //need to check about storage type $table->string('company_profile');//->default('default.jpg'); //need to check about storage type
$table->string('reg_cert');
$table->string('company-name'); $table->string('company-name');
$table->string('registration-no'); $table->string('registration-no');
$table->string('tax-no'); $table->string('tax-no');
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+2 -2
View File
@@ -27,8 +27,8 @@ Route::group(['middleware' => ['jwt.auth']], function() {
return response()->json(['foo'=>'bar']); return response()->json(['foo'=>'bar']);
}); });
}); });
Route::post('/company', 'CompanyController@store'); Route::post('/company', 'CompanyController@store'); //store company information
Route::put('/company/{company}', 'CompanyController@update'); Route::put('/company/{company}', 'CompanyController@update'); //update company information
//Route::post('/company', 'CompanyController@uploadImage'); //Route::post('/company', 'CompanyController@uploadImage');
-2
View File
@@ -1,2 +0,0 @@
*
!.gitignore