diff --git a/app/Company.php b/app/Company.php index bf7df8d..af4bf8d 100644 --- a/app/Company.php +++ b/app/Company.php @@ -7,6 +7,6 @@ use Illuminate\Database\Eloquent\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 = []; } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index b24d69e..c4297d2 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Company; use Image; +use Illuminate\Support\Facades\Storage; class CompanyController extends Controller { @@ -50,21 +51,65 @@ class CompanyController extends Controller // return response()->json(['message'=>'Document not found']); // } $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(); - $img_file = $request->file('company_profile'); + $company_profile = $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')); - return $img_file; - // $file->move('uploads/company_profile/', $img_file); + $file = $request->file('company_profile'); + $ext = $file->getClientOriginalExtension(); - $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(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); } - //$warehouse->address='juhgfd'; - if($request->hasFile('avatar')) + //updating company profile picture + if($file = $request->file('company_profile')) //company profile picture { - $avatar = $request->file('avatar'); - $filename = time() . '.' . $avatar->getClientOriginalExtension(); - Image::make($avatar)->resize(300,300)->save(public_path('/uploads/company_profile/'.$filename)); + $company_profile = $request->file('company_profile'); + $filename = $company_profile->getClientOriginalName(); + //$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'); diff --git a/config/app.php b/config/app.php index f4eaea2..849a78f 100644 --- a/config/app.php +++ b/config/app.php @@ -1,7 +1,7 @@ 'uploads', /* |-------------------------------------------------------------------------- | Application Name diff --git a/database/migrations/2018_04_24_034401_create_companies_table.php b/database/migrations/2018_04_24_034401_create_companies_table.php index a50bae1..2489520 100644 --- a/database/migrations/2018_04_24_034401_create_companies_table.php +++ b/database/migrations/2018_04_24_034401_create_companies_table.php @@ -16,6 +16,7 @@ class CreateCompaniesTable extends Migration Schema::create('companies', function (Blueprint $table) { $table->increments('id'); $table->string('company_profile');//->default('default.jpg'); //need to check about storage type + $table->string('reg_cert'); $table->string('company-name'); $table->string('registration-no'); $table->string('tax-no'); diff --git a/public/company_profile b/public/company_profile new file mode 100644 index 0000000..470ac4c Binary files /dev/null and b/public/company_profile differ diff --git a/public/uploads/company_profile/hello.jpg b/public/uploads/company_profile/hello.jpg index a778bbf..470ac4c 100644 Binary files a/public/uploads/company_profile/hello.jpg and b/public/uploads/company_profile/hello.jpg differ diff --git a/public/uploads/reg_cert/reg_cert.jpg b/public/uploads/reg_cert/reg_cert.jpg new file mode 100644 index 0000000..470ac4c Binary files /dev/null and b/public/uploads/reg_cert/reg_cert.jpg differ diff --git a/routes/api.php b/routes/api.php index 2f0c3a6..890896e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -27,8 +27,8 @@ Route::group(['middleware' => ['jwt.auth']], function() { return response()->json(['foo'=>'bar']); }); }); -Route::post('/company', 'CompanyController@store'); -Route::put('/company/{company}', 'CompanyController@update'); +Route::post('/company', 'CompanyController@store'); //store company information +Route::put('/company/{company}', 'CompanyController@update'); //update company information //Route::post('/company', 'CompanyController@uploadImage'); diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/storage/app/public/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore