The role must have the permission “Browse Admin”
Monthly Archives: December 2018
Customize tinymce in Voyager
Add additional_js:
https://docs.laravelvoyager.com/customization/additional-css-js
‘js/custom.js’ => ‘public/js/custom.js’
Add callback function in additional js:
https://docs.laravelvoyager.com/customization/tinymce
Rename or copy plugin.min.js to plugin.js
TinyMCE will find plugin.js of each plugins in public\vendor\tcg\voyager\assets\js\plugins
https://www.tiny.cloud/docs/advanced/creating-a-plugin/
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
function tinymce_init_callback(editor) { editor.remove(); editor = null; tinymce.init({ selector: 'textarea.richTextBox', skin: 'voyager', min_height: 100, height: 200, resize: 'vertical', plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern code', extended_valid_elements: 'input[id|name|value|type|class|style|required|placeholder|autocomplete|onclick]', file_browser_callback: function (field_name, url, type, win) { if (type == 'image') { $('#upload_file').trigger('click'); } }, toolbar: 'styleselect bold italic underline | forecolor backcolor | alignleft aligncenter alignright | bullist numlist outdent indent | link image table youtube giphy | code', convert_urls: false, image_caption: true, image_title: true, valid_elements:'div[*],p[*],span[*],ul[*],li[*],ol[*],hr,br,img[*],-b,-i,-u', valid_children:'+li[span|p|div]' }); } |
Reference:
- https://github.com/the-control-group/voyager/issues/1945
- Remove doctype and html tags that generated by tinymce automatically: Remove fullpage plugin.
https://stackoverflow.com/questions/17829239/how-can-i-stop-tinymce-from-adding-doctype-htmlhtmlhead-headbody-to-e - https://stackoverflow.com/questions/6266487/tinymce-allow-all-html-tag
- https://stackoverflow.com/questions/7744903/tinymce-allow-data-attribute
Prevent TinyMCE from removing span elements
Menu handler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private function main_menu($menu_id){ $menu = menu('Main', '_json'); //logg($menu); //logg($menu[0]->getTranslatedAttribute('title', 'de', 'en')); $output = '<ul class="list-reset navbar-nav">'; foreach ($menu as $key => $item) { //logg($item); $active = ''; if($item->id == $menu_id){ $active = 'active'; } //$title = $item->getTranslatedAttribute('title', App()->getLocale(), 'en'); $title = lo($item, 'title', App()->getLocale()); $output .= '<li><a class="navbar-item ' . $active . '" href="' . $item->url . '">' . $title . '</a></li>'; } //echo $dom->saveHTML($node); //exit(); $output .= '</ul>'; //logg($output); return $output; } |
Manipulate HTML tags with DOMDocument
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
private function main_menu(){ $menu = menu('Main'); $dom = new \DOMDocument; $dom->loadHTML($menu); //echo $dom->saveHTML(); //exit(); $output = '<ul class="list-reset navbar-nav">'; $xpath = new \DOMXPath($dom); $nodes = $xpath->query("//li"); foreach($nodes as $node) { //Get child node $a = $node->getElementsByTagName('a')->item(0); //If li has active class $a->setAttribute('class', 'navbar-item'); if($node->hasAttributes() == true){ foreach($node->attributes as $attr){ if($attr->nodeName == 'class' && $attr->nodeValue == 'active'){ $a->setAttribute('class', 'navbar-item active'); } } } //Remove active class of li $node->setAttribute('class', ''); $output .= $dom->saveHTML($node); } //echo $dom->saveHTML($node); //exit(); $output .= '</ul>'; //logg($output); return $output; } |
Reference:
Install npm packages for node.js 10 on windows
Install windows build tools
https://github.com/nodejs/node-gyp
Install Visual Studio Build Tools
1 |
npm install -g --production windows-build-tools |
Install Visual C++ 2010 SP1 Dist
https://www.microsoft.com/zh-tw/download/details.aspx?id=13523
Reference:
Laravel Swiftmailer Example
Mailable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use App\Models\Emails; class RegMail extends Mailable { use Queueable, SerializesModels; protected $user = null; protected $reg_email_id = 1; protected $mail_data = null; /** * Create a new message instance. * * @return void */ public function __construct($user) { // $this->user = $user; $this->mail_data = Emails::find($this->reg_email_id); } /** * Build the message. * * @return $this */ public function build() { $data = [ 'subject' => $this->mail_data->subject, 'msg' => $this->mail_data->msg, 'user' => $this->user ]; return $this->subject($data['subject']) ->view('reg_email') ->with($data); } } |
Controller:
1 2 3 4 5 6 7 8 9 10 |
use Illuminate\Support\Facades\Mail; use App\Mail\RegMail; public function test_email(){ $user = new \stdClass(); $user->name = 'Rex'; $result = Mail::to($user)->send(new RegMail($user)); } |
Remove (uninstall) composer package
1 2 3 |
composer require phpmailer/phpmailer composer remove phpmailer/phpmailer |
Reference:
Using Swiftmail to send email in Laravel
- Configs must be in .env. Not working in /config/mail.php (Unknown reason)
2. Add ‘stream’ config in config/mail.php, or you won’t be able to send emails on local machine.
1 2 3 4 5 6 7 |
'stream' => [ 'ssl' => [ 'allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false, ], ], |
3. Debug: /vendor/laravel/framework/src/illuminate/Mail/TransportManager.php
4. Clear config cache. (Optional)
1 |
php artisan config:clear |
Mail Example
1 |
php artisan make:mail RegMail |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use App\Models\Emails; class RegMail extends Mailable { use Queueable, SerializesModels; protected $user = null; protected $reg_email_id = 1; protected $mail_data = null; /** * Create a new message instance. * * @return void */ public function __construct($user) { // $this->user = $user; $this->mail_data = Emails::find($this->reg_email_id); } /** * Build the message. * * @return $this */ public function build() { $data = [ 'subject' => $this->mail_data->subject, 'msg' => $this->mail_data->msg, 'user' => $this->user ]; return $this->subject($data['subject']) ->view('reg_email') ->with($data); } } |
Controller to send email
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Mail; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Carbon\Carbon; use App\Models\B2BMemberM; use App\Mail\B2bRegMail; class Test extends Controller { public function __construct(){ } private function build_data($member){ $params = [ 'id' => $member->id, 'secret' => md5($member->id . $member->email) ]; $url = url('/b2b/verify/?') . http_build_query($params); $data = [ 'verify_url' => $url, 'member' => $member ]; return $data; } public function email(){ $member = B2BMemberM::find(2); //stdClass() works only. Don't user array and collection. $user = new \stdClass(); $user->name = $member->name; $user->email = $member->email; //To test view //$data = $this->build_data($member); //return view('email.b2b_reg', $data); //Mail will return null event email is sent successfully. Mail::to($user)->send(new B2bRegMail($member)); logg('ok'); } } |
Reference:
Upload permission issue
Sometimes php upload won’t work with default system tmp folder. Just create a new one for PHP and change setting in php.ini.
upload_tmp_dir = “C:\phptmp”