How to echo browser locale in laravel 5.2 - laravel

I want to echo the current set locale in my html tag using blade:
<html lang="{{ $locale }}"></html>
I'm new to Laravel 5 and i was wondering how to accomplish this.

If you are asking for locale set in client's browser, you can use request()->server('HTTP_ACCEPT_LANGUAGE') to get those.
And if you are asking for locale set within your Laravel application, you can get it like this: config()->get('locale')
And if you want to get template name in your Laravel blade, just use like this:
// allow $view_name in views
View::composer('*', function ($view) {
View::share('view_name', $view->getName());
});

On top of what #jszobody just said above, you could also make use of javascript and the jstz package in order to find their locale. Assuming you have jQuery installed, your code could look like the following
<script>
$(function() {
$('html').attr('lang', jstz.determine().locale());
}
</script>

Related

Laravel, Revolution Slider - Error when trying to embed

I am trying to add Revolution Slider to my Laravel instance (per instructions from its creators), and so far, I am getting the following error.
Facade\Ignition\Exceptions\ViewException Argument 2 passed to
Illuminate\Translation\Translator::get() must be of the type array,
string given, called in
/home/sasha/Documents/OffProjects/VetPartnersPrintPortal/project/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
on line 878 (View:
/home/sasha/Documents/OffProjects/VetPartnersPrintPortal/project/resources/views/home/index.blade.php)
The setup is quite simple (basic instructions).
class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('home/index');
}
}
View
<?php
include(app_path() . '/Slider/embed.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Example of Revslider embedding</title>
<?php RevSliderEmbedder::headIncludes(); ?>
</head>
<body>
<!-- change "example" in the code below to match your slider's alias -->
<?php
RevSliderEmbedder::putRevSlider('test');
?>
</body>
</html>
Does anyone have any idea what's going on here?
Revolution Slider is a Wordpress plugin, pretty sure it won't work with Laravel. If you click the revolution-slider tag on your question, you'll see that all other questions also have wordpress tag attached to them. I would recommend using sliders designed for Laravel, like this one or this one.
Pavel Lint was wrong. The wordpress and all yours plugin was developed in php, js and mysql. And the laravel is a framework for php...
Why the plugins wont work... I use the same revolution sliver in my projects and this work fine. Is this line of js script just include the "#" before param1, title and param2 like this #{{param1}} | .
This is solve the problem. Enjoy!

Issue with Vue instance in laravel [duplicate]

I want to test a simple vue.js in laravel blade system, Here is my code in test.blade.php view file:
<div id="app">
<p>{{message}}</p>
</div>
<script src="{{url('/assets/js/vue/vue.min.js')}}"></script>
<script>
new Vue({
el:'#app',
data:{
message:"hello world"
}
});
</script>
The problem is while rendering view file laravel wants to access the message as a variable or constant and because there is no any message variable passed to view I get Use of undefined constant exception. So what's the solution?
add #{{message}}
that will tell blade to ignore this.
It's not a good approach to combine the same notation for front-end and back-end. Of course, with the #, Blade can ignore.
A much cleaner idea is to extract the front-end from back-end, because Blade and Vue.js use the same notation:
Front-end with html, css en javascript (in your case Vue.js)
Back-end (in php, Laravel in your case) as REST-api with php that returns json
The big advantages:
It's more secure
It's more maintainable
It's cleaner

Have a problem when used route to controller with variable

I used Laravel route as follow.
Route::get('report/centos7/{id}', 'HomeController#centos7');
And then in Controller, I used this code to return View.
\View::make('report/centos7/', $id);
An error occurred as follow.
InvalidArgumentException in FileViewFinder.php line 137:
View [report.centos7.] not found.
I called the URL like this "mysite/laravelproject/public/report/centos7/result_target2"
I using Laravel 5.2
First time I used this code in Controller
return \View::make('report/centos7/'. $id);
But, the CSS and JS is not loaded. I think because of "."
That is why I changed from "." to ","
Route
Route::get('report/centos7/{id}', 'HomeController#centos7');
HomeController
public function centos7($id)
{
//
return \View::make('report/centos7', $id);
}
I had dynamically added "blade.php" into folder view/report/centos7/xxxx.blade.php
I created a new page to list all files in that folder and link each of the files to show the report in blade format.
I hope Laravel route to Controller is can help to access my report in blade format
Thanks for help. I'm a newbie in programming language
Update
I removed {id} in route as follow
Route::get('report/centos7/{id}', 'HomeController#centos7');
To
Route::get('report/centos7/', 'HomeController#centos7');
And removed id in HomeController as well
It works. But, I still want to send $id from Route to HomeController
When I do that I don't know why CSS is not loaded in my blade php.
Please help.
Update (Sovled)
Thank god everyone
If anyone has the same problem as me
I changed my href into the layout as follow and it works.
<link href="{{ URL::asset('theme/vendor/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
The main issue is the extra / in your view code:
\View::make('report/centos7/', $id);
If you change it to the following, it should all work correctly:
\View::make('report.centos7', $id);
Make sure that your HTML code is in the resources/views/report/centos7.blade.php file.

Adding javascript function to a grocerycrud add or edit form

Is it possible to add a javascript function to the add/edit forms of grocery_CRUD?
E.g. As a user is typing in a particular field when adding or editing a record I want to execute a javascript on the keydown event.
If so, how?
It is possible.
For example, you call the view like this:
$this->load->view('grocery_crud_view', $output);
In the beginning of the view (grocery_crud_view.php), you can add any javascript
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascrpt">
$("#field-code").keyup(function(){
alert("there is a keyup");
});
</script>
<?php
// The rest of default php code
?>
Most of the id of the grocery-CRUD view (if you use flexigrid theme) would be something like this : "field-your_field_name"
You can inspect with firebug or google-chrome developer tools to ensure it.

Recaptcha translation

Does anyone know how to change text language from Recaptcha?
I've already tried:
<script type="text/javascript">
var RecaptchaOptions = {
lang : 'fr',
};
</script>
But it doesn't change.
For the reCAPTCHA V2 widget you can override the default interface language detection as a parameter to the javascript. See the new docs.
<script src="https://www.google.com/recaptcha/api.js?hl=fr"></script>
set your lang at last of api address (persian "farsi"):
https://www.google.com/recaptcha/api.js?hl=fa
find your language short name in https://developers.google.com/recaptcha/docs/language
Append &hl=fr to the public key.
Appending the language code to your public key work very well :
define('RECAPTCHA_PUBLIC_KEY', '__YOUR_PUBLIC_KEY_HERE__&hl=fr');
echo recaptcha_get_html(RECAPTCHA_PUBLIC_KEY);
So you can remove your JavaScript from your code. Or leave it if you use other options, but remove "lang:'fr'"
If you mean the language in the actual images that you are trying to solve, unfortunately you can't change the language of that text, at least not yet. The only thing you can change is the language of the interface (the text/prompt in the widget, etc.).
Response to comment: well, according to the docs, you seem to have it right. Is this code place in the same page where the widget appears?
The docs also say:
you need to add the following code in your main HTML page anywhere before the <form> element where reCAPTCHA appears (this will not work if placed after the main script where reCAPTCHA is first invoked)
so also make sure that this code is placed before the <form> tag which encloses the reCAPTCHA widget.
RecaptchaOptions is never working.
Another solution is to add a parametrt hl= langCode while we including the captcha script
<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . &hl=de">/script>
You pasted the incorrect js. There should not be a comma after lang: 'fr'. The correct code is:
<script type="text/javascript">
var RecaptchaOptions = {
lang : 'fr'
};
</script>

Resources