How to use / retrieve Laravel translations in JS? - laravel

I am using Laravel translations like:
{{trans('general.myIdText')}}
or with
<?php __('general.myIdText'');?>
I have no idea on how to retrieve 'general' texts in JS
I tried like
var trans = JSON.parse(<?=trans();?>);
I can also see many properties with
<?php print_r(trans());?>
But this also contains many "protected properties"
Any way to do it ?

Related

CodeIgniter 4 view

Any one can tell me how to view a PHP page in a new tab from CodeIgniter 4 controller. I tried this code:
return view('/pdfrepo/resume-page-pdf',$data, array('target' => '_blank'));
the page is viewed with no error at all, but on the same tab!.
rendering a view is not the same as clicking on a link:
rendering a view:
if you look at the docs Global Functions and Constants - view you'll see that third "options" parameter you are using is meant for a completely different concept as you try to apply it to, like the styling of an <a href>, which in your example doesn't even exist (yet):
$options (array) – An array of options that will be passed to the
rendering class.
Currently, these options are available for use within the $options array: saveData, cache, debug
clicking a link:
check the documentation URL Helper - anchor where you would use the attributes parameter to add something like: ['target' => 'blank'] to achieve a link which opens a new tab
P.S.
_blank:
usually a new tab, but users can configure browsers to open a new
window instead.
PHP can't open a new tab and display the data. PHP is a Server Side Language. for this, you have to use a Client Side Language such as JavaScript.
In your main view
View PDF
target="_blank" which performs the miracle that loads the page in a new tab.

How to dynamically load/render Laravel Collective form?

I'm devising a small CMS for the in-house development team, where all have experience working with laravel.
The CMS requires a small feature where the services that are listed can have a quotation form attached. Instead of creating a completely separate module to add elements & other separately, I wanted to have the system in a manner that the developer adds the laravel collective form code, which we store in the database.
While retrieving, we render the form server side.
Here's my implementation
Controller
public function show($id)
{
$data['page'] = Service::where('slug', $id)->first();
if ($data['page']) {
....
$data['form'] = $data['page']->quoteform()->first();
....
And in the view
{!! $form['html'] !!}
But this is definitely won't help, so I tried this approach of rendering the collective form
$data['form'] = View::make('website.includes.render-form',['form'=>$data['page']->quoteform()->first()]);
But I'm not sure if this should work, as I couldn't make it work.
Looking forward to a solution if at all the approach I choose is possible, if yes or can be done, would like to know more on the same.
TIA
Edit 1:
I used the following blade command Blade::compileString('string here') which helped to a certain extent.
where I'm getting the following result
You can render the HTML of a view using render() method. So you can update to this :
$data['form'] = View::make('website.includes.render-form',
['form' => $data['page']->quoteform()->first()]
)->render();
Now the $data['form'] will have rendered HTML which you can use in blade using {!! $data['html'] !!} if you are passing $data to your main view.

Roles and permissions issues in laravel project

I am working on a laravel project. I have a side menu that is persistent across all pages. However the menu items to be shown is dependent on the role assigned to the user. I achieved that by doing this:
<?php
/**$links = Session::get('links'); **/
use Illuminate\Support\Facades\DB;
$id_hr_employee= Auth::user()->id_hr_employee;
$links = DB::select("select a.link as links from sys_menu_links as a a.id_hr_employee = $id_hr_employee)
");
?>
#if(isset($links))
#foreach($links as $link)
<li><hr class="light-grey-hr mb-10"/></li>
#include("$link->links")
#endforeach
#endif
This works quite alright. However, if someone enters a route to a menu (that he is not assigned to) on the address bar, he sees that page.
Please how do I prevent this?
i would highly recommend you using laratrust: https://laratrust.readthedocs.io/en/4.0/.
And to secure your sides: 1.option work with middelware to Block your admin views 2. Option Check for permission in the Controller files.
As a guidance you could look up this tutorial: http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from-scratch-tutorialexample.html
greetings

joomla Modules - Between Article or inside Article? What is correct?

I want to place articles and modules on my page. It should look like my scatch:
I am wondering if i can make 4 articles and one module (information box) and place this inbetween those articles, Or should i just create one article wich looks like the hole area (article 1-4 + INformation box)? So far i have tried to do {loadposition infobox-pos} into article 2. But than the box-width is not 100% but 50%.
Than aggain if i would make one big article with the contents from article 1-4 it would not fit great into my responsive layout.
I use T3-Framework.
Joomla doesn't support this natively, since module output is controlled by the template, and component output (in this case, com_content, view=category, layout=blog) is handled before modules are rendered.
You can proceed in many ways, I am listing them in order of decreasing ease:
Write a jquery script that moves the pieces in the browser. You could also use mootools and it's bundled with joomla, but odds are you already have jquery loaded anyways.
Write a view override for abovementioned view: so copy /components/com_content/view/category/tmpl to /templates/your_template/html/com_content/category (copy all files). Then edit blog.php and insert your module there, use something like /plugins/content/loadmodule/loadmodule.php :
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$modules = JModuleHelper::getModules($position);
$params = array('style' => $style);
foreach ($modules as $module) {
echo $renderer->render($module, $params);
}
Write a content plugin
you can also use {loadmodule YourCustomModuleTitle} and place this in <div> with custom style attributes like
<div style="width:100%;float:right">{loadmodule MyModule}</div>
or
<div class="something">{loadmodule MyModule}</div>
Note: the module which loaded must be assigned to the same menu item or "all"

DHTMLX calendar enable / disable in whole website

I am working on website (built using PHP, Mysql, jQuery) which require that admin set a variable in configuration and according to that configuration variable jQuery autocomplete is enabled or disabled to all website. Is there any way to achieve that functionality.
The easiest way to do it is to add a common id, or other attribute to all the parent elements where the schedule shows up. Then include into your main javascript file something of the form
FLAG = 1; //for visibile, or 0 for invisible
$('#calendar').toggle(FLAG); //OR
$('[rel=calendar]').toggle(FLAG);
If you wanted that to come from php, you can always load your javascript within php:
functions.js.php:
FLAG = <?php $CAL_SETTING ?>
//go on with the rest of the javascript
//then include it into your html
<script language="javascript" src="functions.js.php"></script>
Good luck!
create a table setting with these fields [name, value,..] and set the name calendar_status value hide
in your view you can get read of that field from you DB and set the myCalendar.hide(true); or myCalendar.hide(false);
myCalendar = new dhtmlXCalendarObject("DateStart");
myCalendar.hide(); <- you php code like <?php echo calendar_status; ?>

Resources