Regarding the Laravel documentation, the #yield directive in a blade template can have a default value as second argument. Since I'm developing a multi language site, how is it possible to use the #lang directive as default value?
I've already tried:
#yield('title', #lang('title'))
#yield('title', lang('title'))
neither of them is working.
Use Lang::get() or trans() to get the localized version of your string:
#yield('title', trans('title'))
Related
I'm using the Varbox 2.x paid platform in one of my projects and I have a question regarding translatable models.
I have a News custom entity on which I've applied the HasTranslations trait in order to support title and content in multiple languages.
Everything works great and the admin crud also supports multi-language.
Also, in my frontend I've noticed that by accessing $news->title (just normal Laravel syntax) returns the value for the locale I'm currently on.
I was wondering if for example I could get the title in English, even if my locale is set to fr.
Thanks! Great work creating this package!
Yes, it is possible to get any attribute's value in any of the supported languages, regardless of your set locale, by using the getTranslation method.
$news = News::find($id);
$titleInEnglish = $news->getTranslation('title', 'en');
Here's the doc section for reference: https://varbox.io/docs/2.x/translatable-models#get-translation
Also, regarding what you've said that accessing $news->title returns the value for the locale you're currently set to, yes, that's true.
That's done inside the Varbox\Traits\HasTranslations trait, namely inside the getAttribute method (which actually uses the same getTranslation method, but with your set locale by default).
This is done to ease the implementation process, thus keeping it Laravel friendly :)
Having trouble with vuelidate.
This is working code with the same nesting level and names for validation and v-model:
_https://jsfiddle.net/submarina/oxsvm5c6/
And here I am using different names for model/validation rule:
_https://jsfiddle.net/submarina/cwhx48q5/
This variant doesn't work too (validation rule is nested, v-model is not):
_https://jsfiddle.net/submarina/gbu9Lkq3/
It doesn't work, you may check $v object.
So the question is why?
Doesn't it allowed to use different name for v-model and related validation rule object?
You didn't replace all occurrences of usernameA to usernameB in both a template and a code (for the second link). I replaced them and it now works like on the first link
I'm trying to use laravel component and slot.
As I'm using blade templates under components folder, my blade syntax is something like this
#component('components.button',['data'=>$data])
#endcomponent
Here, every times I call it, I have to write the word "component" multiple times.
can I shorten it as below?
#component('button',['data'=>$data])
If yes, how can I achieve it?
You must use of Aliasing Components functionality
If your Blade components are stored in a sub-directory, you may wish to alias them for easier access. For example, imagine a Blade component that is stored at resources/views/components/alert.blade.php. You may use the component method to alias the component from components.alert to alert. Typically, this should be done in the boot method of your AppServiceProvider:
Blade::component('components.alert', 'alert');
Referense
I'm using latest Laravel 5.4. My site is configured to use German and English languages. So for instance, I have a login page for German:
http://localhost/de/login
and for English:
http://localhost/en/login
What I've done is I created a Language middleware that looks at the first segment of the URI ('en' or 'de') and sets proper app()->setLocale() based on the first segment value. What I'm struggling with is how do I generate links (properly / best practice) for such routes. What function should I use in my blade templates to generate such links. I tried route('login', app()->getLocale()) but it's giving me something like this: http://localhost/en/login?de. Why is this happening? What's the function I should be using to generate links to named routes and unnamed routes?
Thanks,
Z
Try this:
Route::post('page/{locale?}', 'PageController#someMethod')->where(['locale' => 'de|en|es|fr|it|nl']);
See, if this works!
I would like to include a file on my index page. In php I use something like include('include/header.php');
or in larvel 4 I used include(app_path().'/views/includes/header.php');
My question is...How is it done in Laravel 5 since the whole framework has changed folder structures and what not? It seems that app_path() is not longer valid. Also, I do not want to leverage blade syntax. Does anyone have an idea on this?
Use base_path because the views are not outside off the app directory. Also you can pass the path to the function, no need for string concatenation
include(base_path('resources/views/includes/header.php'));
Try it like this:
include(app_path().'/../resources/views/includes/header.php');