How to use webklex AttachmentMask class getContentBase64Encoded or getImageSrc - laravel

I am having problems using the getImageSrc and getContentBase64Encoded under the AttachmentMask::class webklex.
The error message shows Method Webklex\IMAP\Message::getImgSrc() is not supported and Method Webklex\IMAP\Message::getContentBase64Encoded () is not supported.
$oClient = new Client([
'host' => $imap['host'],
'port' => $account->imap_port_no,
'encryption' => $ssl,
'validate_cert' => true,
'username' => $account->user_name,
'password' => $account->password,
]);
$oFolder = $oClient->getFolder($folder_name);
$oMessage = $oFolder->getMessage($message_id, null, null, true, true, true);
$test = $oMessage->getImgSrc();
//or this
$test = $oMessage->getContentBase64Encoded();

got it working already using these line of codes.
$attachment_mask = \Webklex\IMAP\Support\Masks\AttachmentMask::class;
$oClient->setDefaultAttachmentMask($attachment_mask);
$attachment = $oMessage->getAttachments()->first();
$masked_attachment = $attachment->mask();
$link = $masked_attachment->getImageSrc()
;

Related

Get all messages in chunks with Php-imap Webklex

``
Excuse the English of translator
I am trying to consult emails in parts since there are more than 4000 to process them, I am working with Laravel and phpimap, I have tried everything, I start programming and I do not understand much of this
I practically just opened the connection, my plan is to use jobs to get those emails in the background but, for now I need to get them since I can't find how
public function index()
{
$account= new mailModel();
$cm = new ClientManager($options = []);
$messages= new MessageCollection($perPage = 500, $page = 6, $pageName = 'page');
#$message= new Message();
$client = $cm->make([
'host' => 'mail.spamanalizer.ibx.lat',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => '',
'password' => '',
'protocol' => 'imap'
]);
//Connect to the IMAP Server
$client->connect();
$query=new WhereQuery($client);
$folder = $client->getFolderByName('Recibidos');
$query->all()->chunked(function($messages, $chunk){
/** #var \Webklex\PHPIMAP\Support\MessageCollection $messages */
dump("chunk #$chunk");
$messages->each(function($message){
/** #var \Webklex\PHPIMAP\Message $message */
dump($message->uid);
});
}, $chunk_size = 50, $start_chunk = 1);
echo "<pre>".print_r($messages, true)."</pre>";
}

Trying to generating QR in laravel but get error Use of undefined constant

I am trying to pass code to generate a QR using chart.googleapis.com but I get Use of undefined constant
I can successfully do it here https://staging.veev.app/events/39 but I am having no luck doing it here https://staging.veev.app/groups/2/Young%20Professionals%20LA. Below is the code.
curl_close($ch);
$result = json_decode($result, true);
return $this->_loadView('client.pages.group')->with('group', $result);
$this->data['group'] = $result;
$group = $this->data['group'];
$group_data = array(
'prefix' => 'veev-groups',
'version' => 1,
'group_id' => $group['id'],
'group_name' => $group['name'],
//'group_name' => $group['result'],
//'merchant_id' => $group['merchant_id'],
'type' => 'groups',
'webpage' => $this->site_baseurl.'/groups/'.$group_id
);
$group_data = array_values($group_data);
$group_data = join("|||", $group_data);
$this->data['page_name'] = $group['name'];
$this->data['qr_srctest'] = 'https://chart.googleapis.com/chart?cht=qr&chs=250x250&chld=H%207C0&chl=' . $group_data;
return $this->_loadView('client.pages.group')->with('group', $result);

Where is the file after create by "$service->spreadsheets->create($requestBody)"

Thank you very much for reading this, its quite long!
I run my function:
public function createSpreadSheet()
{
$client = $this->getClient();
$service = new \Google_Service_Sheets($client);
// TODO: Assign values to desired properties of `requestBody`:
$requestBody = new \Google_Service_Sheets_Spreadsheet();
$response = $service->spreadsheets->create($requestBody);
echo '<pre>', var_export($response, true), '</pre>', "\n";
}
I got a result:
Google_Service_Sheets_Spreadsheet::__set_state(array(
'collection_key' => 'sheets',
'developerMetadataType' => 'Google_Service_Sheets_DeveloperMetadata',
'developerMetadataDataType' => 'array',
'namedRangesType' => 'Google_Service_Sheets_NamedRange',
'namedRangesDataType' => 'array',
'propertiesType' => 'Google_Service_Sheets_SpreadsheetProperties',
'propertiesDataType' => '',
'sheetsType' => 'Google_Service_Sheets_Sheet',
'sheetsDataType' => 'array',
'spreadsheetId' => '1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU',
'spreadsheetUrl' => 'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit',
'internal_gapi_mappings' =>
array (
),
modelData' =>
array (
),
'processed' =>
array (
),
'properties' =>
Google_Service_Sheets_SpreadsheetProperties::__set_state(array(
'autoRecalc' => 'ON_CHANGE',
'defaultFormatType' => 'Google_Service_Sheets_CellFormat',
'defaultFormatDataType' => '',
'iterativeCalculationSettingsType' => 'Google_Service_Sheets_IterativeCalculationSettings',
'iterativeCalculationSettingsDataType' => '',
'locale' => 'en_US',
'timeZone' => 'Etc/GMT',
'title' => 'Untitled spreadsheet',
'internal_gapi_mappings' =>
array (
),
'modelData' =>
array (
),
'processed' =>
array (
),
'defaultFormat' =>
Google_Service_Sheets_CellFormat::__set_state(array(
'backgroundColorType' => 'Google_Service_Sheets_Color',
'backgroundColorDataType' => '',
'bordersType' => 'Google_Service_Sheets_Borders',
'bordersDataType' => '',
'horizontalAlignment' => NULL,
'hyperlinkDisplayType' => NULL,
'numberFormatType' => 'Google_Service_Sheets_NumberFormat',
'numberFormatDataType' => '',
.........
.........
))
I access to the link it returned:
'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit'
it gives me this 'request access' page, then I press the request access
I open my email and get this:
Your message wasn't delivered to xxxxxx#xxxxxxxx.iam.gserviceaccount.com because the domain admanager-1x3x71x4x27x4.iam.gserviceaccount.com couldn't be found. Check for typos or unnecessary spaces and try again.
Is there something wrong and what should I do? I just want to open the file and check where it is.
Thank you very much!

Edit Form in Laravel: Creates New Entry instead of Updating Old Data

I tried to create edit method on form data submission, but instead of updating the old entry, it creates a new entry in the database.
My source files are:
web.php
Route::get('/input_gedung_bangunan/{id_bangunan}', 'input_gedung_bangunan#tampiledit');
Route::post('/data_gedung_bangunan/hitung_data', 'input_gedung_bangunan#store');
Controller:
public function store(Request $request){
//DB::enableQueryLog();
//$id_bangunan = $id;
$validation = \App\Tbl_uraian_datas::where('id_bangunan', '=', $request->get('id_bangunan'))->first();
if(is_null($validation)){
$tbl_uraian_datas = new \App\Tbl_uraian_datas;
$tbl_uraian_datas->id_bangunan = $request->get('id_bangunan');
$tbl_uraian_datas->id_kanwil = Input::get('IDKanwil');
$tbl_uraian_datas->id_kota_kab = Input::get('IDKotaKab');
$tbl_uraian_datas->nomor_baris = Input::get('NomorBaris');
$tbl_uraian_datas->nama_bangunan = Input::get('NamaBangunan');
$tbl_uraian_datas->alamat_bangunan = Input::get('AlamatBangunan');
$tbl_uraian_datas->nama_kota_kab = Input::get('Kota/Kabupaten');
$tbl_uraian_datas->kode_barang = Input::get('KodeBarang');
$tbl_uraian_datas->nup_barang = Input::get('NUPBarang');
$tbl_uraian_datas->luas_lantai = Input::get('LuasLantai');
$tbl_uraian_datas->jumlah_lantai = Input::get('JumlahLantai');
$tbl_uraian_datas->tahun_penilaian = Input::get('TahunPenilaian');
$tbl_uraian_datas->tahun_dibangun = Input::get('TahunDibangun');
$tbl_uraian_datas->tahun_direnovasi = Input::get('TahunDirenovasi');
$tbl_uraian_datas->id_jenis_bangunan = Input::get('IDJenisBangunan');
$tbl_uraian_datas->jenis_bangunan = Input::get('JenisBangunan');
$tbl_uraian_datas->id_kategori = Input::get('IDKategoriBangunan');
$tbl_uraian_datas->kategori_bangunan = Input::get('KategoriBangunan');
$tbl_uraian_datas->id_kondisi = Input::get('IDKondisiBangunan');
$tbl_uraian_datas->kondisi_bangunan = Input::get('KondisiBangunan');
$tbl_uraian_datas->luas_carport = Input::get('LuasCarport');
$tbl_uraian_datas->panjang_pagar_material1 = Input::get('PanjangPagar1');
$tbl_uraian_datas->panjang_pagar_material2 = Input::get('PanjangPagar2');
$tbl_uraian_datas->panjang_pagar_material3 = Input::get('PanjangPagar3');
$tbl_uraian_datas->harga_per_m2 = Input::get('Hargaperm2');
$tbl_uraian_datas->alasan_fisik = Input::get('Alasan1');
$tbl_uraian_datas->penyusutan = Input::get('Penyusutan');
$tbl_uraian_datas->alasan_penyusutan = Input::get('Alasan2');
$tbl_uraian_datas->save();
}else{
//Edit Data Gedung/Bangunan
$tbl_uraian_datas = \App\Tbl_uraian_datas::update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
//$tbl_hasil_perhitungans = \App\Tbl_hasil_perhitungans::where('id_bangunan', '=',$request->get('id_bangunan'))->update(['umur_efektif_bangunan' => Input::get('nUmurEfektifBangunan'), 'pembulatan' => Input::get('nPembulatan')]);
$request->session()->flash('alert-success', 'Data Gedung Bangunan was successfully added!');
return back();
}
}
It looks like the controller keeps making the new id for the editted data and I don't know what I did wrong in my controller.
Instead of the following lines in your code:
$validation = \App\Tbl_uraian_datas::where('id_bangunan', '=', $request->get('id_bangunan'))->first();
if(is_null($validation)){
Try this:
$validation = \App\Tbl_uraian_datas::where('id_bangunan', $request->input('id_bangunan'))->first();
if(empty($validation)){
AND
instead of
$tbl_uraian_datas = \App\Tbl_uraian_datas::update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
Try:
$tbl_uraian_datas = \App\Tbl_uraian_datas::where('id_bangunan',$request->input('id_bangunan'))->update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
You need to tell which row to actually update by giving a where clause

laravel save pdf no such file or directory

So I want to save a pdf file to a directory on my local server but it keeps saying that the directory does not exist.
So first of all where would you store PDF files that are not accessible to by externals (so not in the public folder).
So this is my code. The download works perfectly.
public function generatePDF()
{
$this->mailorder = Session::get('order');
$this->cart = Session::get('cart');
$data = [
'id' => $this->mailorder->id,
'client' => $this->mailorder->Contact,
'country' => $this->mailorder->country,
'city' => $this->mailorder->city,
'street' => $this->mailorder->street,
'postal' => $this->mailorder->postal,
'phone' => $this->mailorder->phone,
'email' => $this->mailorder->email,
'dateIn' => $this->mailorder->dateIn,
'dateOut' => $this->mailorder->dateOut,
'subtotal' => $this->mailorder->subtotal,
'tax' => $this->mailorder->tax,
'total' => $this->mailorder->total,
'cart' => $this->mailorder->cart,
'delivery' => $this->mailorder->delivery,
];
$path = "order_{$this->mailorder->id}_{$this->mailorder->Contact}";
$pdf = PDF::loadView('pdf.orderConfirmationPdf', $data)->save('storage/app/public/'.$path.'.pdf');
;
return $pdf->download(''.$path.'.pdf');
}
First of all, you should check if the directory exists with File facade. If it does not exist, you must make the directory.
if(!File::exists($directory_path)) {
File::makeDirectory($directory_path);
}
If the error still occurs, you must force it to make the directory:
if(!File::exists($directory_path)) {
File::makeDirectory($directory_path, $mode = 0755, true, true);
}
After that, you can save the file in that directory.
Second, if you don't want to save the file in the public directory. you must save it in storage.By simply call storage_path($file_path). this way laravel saves the file under storage/app/public directory.
after that, you can get the URL of the file according to this answer.
I figured it out thank you for your answer.
This is my code:
public function generatePDF()
{
$this->mailorder = Session::get('order');
$this->cart = Session::get('cart');
$data = [
'id' => $this->mailorder->id,
'client' => $this->mailorder->Contact,
'country' => $this->mailorder->country,
'city' => $this->mailorder->city,
'street' => $this->mailorder->street,
'postal' => $this->mailorder->postal,
'phone' => $this->mailorder->phone,
'email' => $this->mailorder->email,
'dateIn' => $this->mailorder->dateIn,
'dateOut' => $this->mailorder->dateOut,
'subtotal' => $this->mailorder->subtotal,
'tax' => $this->mailorder->tax,
'total' => $this->mailorder->total,
'cart' => $this->mailorder->cart,
'delivery' => $this->mailorder->delivery,
];
$filename = "order_{$this->mailorder->id}_{$this->mailorder->Contact}";
$path = storage_path('pdf/orders');
if(!File::exists($path)) {
File::makeDirectory($path, $mode = 0755, true, true);
}
else {}
$pdf = PDF::loadView('pdf.orderConfirmationPdf', $data)->save(''.$path.'/'.$filename.'.pdf');
;
return $pdf->download(''.$filename.'.pdf');
}

Resources