Monthly archives: September, 2018

How to add select form element in Angular html component file?

.ts: all_lines = [ {id: 1, name: “Line 1”}, {id: 2, name: “Line 2”}, {id: 3, name: “Line 3”}, {id: 4, name: “4”}, {id: 5, name: “5”}, {id: 6, name: “6”}, {id: 7, name: “7”}, {id: 8, name: “8”}, {id: 9, name: “9”}, ]; .html: <select formControlName=”lines” class=”form-control”> <option *ngFor=”let line of all_lines” [ngValue]=”line.id”>{{line.name}}</option> </select>

How to use my owner class in Laravel?

Create a php class file in App\Libraries, eg. CupsPrinter.php namespace App\Libraries; use Smalot\Cups\Builder\Builder; use Smalot\Cups\Manager\PrinterManager; use Smalot\Cups\Transport\Client; use Smalot\Cups\Transport\ResponseParser; use Smalot\Cups\Manager\JobManager; use Smalot\Cups\Model\Job; class CupsPrinter { private $cups_user; private $cups_pass; private $cups_ipp_uri; function __construct($cups_user, $cups_pass, $cups_ipp_uri) { $this->cups_user = $cups_user; $this->cups_pass = $cups_pass; $this->cups_ipp_uri = $cups_ipp_uri; } /** * cups print pdf function * * …

How to run a onclick javascript function when use Angular ngNoForm

<form target=”_blank”id=”pdf_form”action=”/backend/pdf” ngNoForm method=”post” class=”pdf-request”> ….. <button type=”submit”class=”btn btn-info btn-sm mr-2 ” (click)=”printPdfNow(‘Yes’)”><i class=”fa fa-print mr-1 ml-2″ aria-hidden=”true”></i>Print Now</button> <input type=”hidden”name=”print_now”value=”No” /> …. </form> js function in Angular xxx.ts: printPdfNow(print_or_not: string) { let f = <HTMLFormElement>document.getElementById(‘pdf_form’); console.log(f.print_now.value); if (print_or_not == ‘Yes’) { if (confirm(‘Are your sure to print the harvest slip(s) automatically?’)) { f.print_now.value = …

How to fix Malformed UTF-8 characters, possibly incorrectly encoded while upload CSV file

Actually, it not related to upload csv file, but there might be some non-utf8 characters when edit csv file which cause this error Malformed UTF-8 characters, possibly incorrectly encoded $importFiles = SomeModel::updateOrCreate( [ ‘someid’ => utf8_encode($item[‘someid’]) ], [ ‘name’ => $item[‘THE NAME’], ‘date’ => $item[‘THE Date’], or we can use: mb_convert_encoding($item[‘EID’], ‘UTF-8’, ‘UTF-8’);

Why the php generated PDF file in different font and size? How to display image for php dompdf?

First, only few standard font supported: The PDF specification requires that PDF readers support a core set of fonts. These fonts are as follows: Courier (Normal, Bold, Oblique, and BoldOblique variants) Helvetica (Normal, Bold, Oblique, and BoldOblique variants) Times (Normal, Bold, Oblique, and BoldOblique variants) Symbol ZapfDingbats Then, the html and body css style has …

How to pass value in Angular form using PUT method for update laravel api?

Laravel PUT method usually used for update, but can’t get data/value from upload file. How to pass value in Angular form using PUT method for update laravel api? html form: <form class=”w-75″ [formGroup]=”main_form” (ngSubmit)=”onSubmit()” enctype=”multipart/form-data”> <div class=”form-row”> <input class=”form-control-file” (change)=”fileChange($event)” type=”file” name=”avatar_file” formControlName=”avatar_file” placeholder=”Upload file”accept=”.png,.jpg,.jpeg,.gif” id=”avatar_file”> .ts: avatar_file: new FormControl(undefined),  //use undefined to avoid console …

How to set web user session login and csrf token after passport oauth api login in Angular

When post a passport oauth api login in Angular, set login api use web routes middleware. web.php: Route::post(‘/api/v1/login’, ‘API\[email protected]’); instead of use api.php: Route::post(‘login’, ‘[email protected]’); This will set a laravel_session in cookie, and you will only need use Angular http post request login once, no need to login from web form again. You can directly …

How to add/send Authorization Bearer access_token request header to get/retrieve user information

Here, we use Laravel Middleware changing header before passing to controller App\Http\Middleware\CheckAccessToken.php: namespace App\Http\Middleware; use Closure; class CheckAccessToken { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (isset($_COOKIE[‘access_token’])) { $request->headers->set(‘Authorization’, ‘Bearer ‘ . $_COOKIE[‘access_token’]); } //dd($request->headers); return …

How to set access token cookie while login via passport oauth2

protected function authenticated(Request $request, $user) { $username = $request->input(’email’); // if ( $request->username !== null ) { // $username = $request->input(‘username’); // } $password = $request->input(‘password’); $request->request->add([ ‘username’ => $username, ‘password’ => $password, ‘grant_type’ => ‘password’, ‘client_id’ => env(‘OAUTH2_CLIENT_ID’), ‘client_secret’ => env(‘OAUTH2_CLIENT_SECRET’), ‘scope’ => ‘*’ ]); $tokenRequest = Request::create( env(‘APP_URL’) . ‘/oauth/token’, ‘post’ ); $token_json …