Category «Laravel»

How to download/display bolb/bytea file from database use Laravel

We should use raw query instead of eloquent of laravel: $uploadedFile = $this->uploadedFileRepository->findWithoutFail($id); $f = \DB::table(‘uploaded_files’) ->selectRaw(‘*’) ->where(‘id’, ‘=’, $id) ->first(); $file_bytea = stream_get_contents($f->file_content); if (function_exists(‘pg_unescape_bytea’)) { $file_str = pg_unescape_bytea($file_bytea); } else { $file_str = pack(‘H*’, $file_bytea); } header(“Content-type:”.$f->mime_type); //if (strpos($f->mime_type, ‘image’) === false && strpos($f->mime_type, ‘pdf’) === false) { header(“Content-Disposition: attachment; filename=”.$f->file_name); //} echo$file_str; …

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 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 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 …

How to resolve Laravel php artisan migrate Undefined table: 7 ERROR: relation does not exist

create a new database test002 $ php artisan migrate Illuminate\Database\QueryException : SQLSTATE[42P01]: Undefined table: 7 ERROR: relation “extractees” does not exist Exception trace: 1 App\Console\Commands\ImportCsvFile::__construct() => Means something wrong is here ImportCsvFile after fix above issue, new error happened: $ php artisan migrate Illuminate\Database\QueryException : SQLSTATE[42P01]: Undefined table: 7 ERROR: relation “users” does not exist …