Laravel Localization Language Switcher using currentRouteName pass argument - laravel-5

I am having an issue with language switcher, when trying to execute a route with more than one parameter
I get following error message
Missing required parameters for [Route: client.edit] [URI: {language}/client/{id}/edit].
in the header having an switcher code Route::currentRouteName()
<ul class="dropdown-menu" role="menu">
<li>EN</li>
<li class="divider"></li>
<li>AR</li>
</ul>
I tried below code, it is not working
<?php if(isset(request()->id)) { ?>
<li>EN</li>
<li class="divider"></li>
<li>AR</li>
<?php } else { ?>
<li>EN</li>
<li class="divider"></li>
<li>AR</li>
<?php } ?>

I have such kind of question due to every time when we use some routes, where have to send 1 and more parameters (I'm not talking about `language`) like `{id}`, `{category}` or something else, for example in your route: `/client/{id}/edit` - this kind of situation can be greatly passed but with out native multi-language implementation.
By truth, I've tried to use several variations with Middleware, ServiceProviders and else, but, the best way that I've understand is to use ready-made solution with support and going forward to reach dev. goals.
That's why I recommend you to use this package (mcamara/laravel-localization). They have already made cool functionality like route localization, standard support of many countries and some features that could be useful in the future.
Also, you will have to edit you current scripts to remove old made-localization by yourself or someone else and follow the instructions. I hope you will enjoy!

Related

Is it recommended to make general partials for modals, drop-downs etc in Laravel Blade?

I am looking for a very general way to include bootstrap components in my blade view. For example let's say I need a drop down in my view, should I make a partial called dropdown.blade.php with code as follows:
<div class="dropdown">
<a href="#" class="dropdown-toggle" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-chevron-down"></span></a>
<ul class="dropdown-menu">
#foreach ($options as $option)
<li>{{$option["name"]}}</li>
#endforeach
</ul>
</div>
and use it in my view in the following way:
#include('partials.dropdown',
array("options"=>array(
["href"=>"#", "name"=>"Profile"],
["href"=>"#", "name"=>"Report"],
)))
Even we can make it more generic by adding options for button name etc. Is it a good or preferable way to do it or should we use copy-paste method from bootstrap website to our views every time? Is there any package that is doing this sort of work? Can we make it in more elegant way?
This seems like a good idea if you are going to re-use the component a lot. I think the more elegant way to do it would be to create custom blade directives:
https://laravel.com/docs/master/blade#extending-blade
Then you could do, for instance:
#dropdown($options, 'btn-primary')
I would also provide an argument for a custom element ID or name, so you can reference it elsewhere on the page as needed.
This gets a little more complex with things like modals. I think you'd want to register multiple blade directives so you could do something like
#startmodal
#modaltitle('Title')
#startmodalbody
Some body content
#endmodalbody
#endmodal

How to pass value from Dashing's .erb to the job (.rb)

I want to use a widget twice on my Dashing dashboard, but with different options. I'd like to set those options in the html like so:
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="myweather" data-view="myweather" data-offset="0">
</li>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="myweather" data-view="myweather" data-offset="1">
</li>
The theory being I can have both Now and In-One-Hour weather widgets, but I can't workout how to get the offset value in the job file so that I can use it for fetching the data.
Adding this as an answer since I do not have 50 points to just comment.
I don't believe this is possible. The way dashing works is that all communication goes from the server, a.k.a. jobs, to the web client. Notice how the jobs are started even before you load one page, so they do not know what channels are currently displayed. You can create multiple channels (myweather-offset-0, myweather-offset-1, etc) and send_event to all of them.
Yes, it is possible. But, I am not sure how you are planning to use.
You would have to modify the .html file of the corresponding widget to pass values.
For example, in my 'list' widget's .html I can do (added second tag)
<h1 class="title" data-bind="title"></h1>
<h1 class="title" data-bind="myown"></h1>
In my .erb I can bind myown like this (at the end).
<div data-id="buzzwords" data-view="List" data-unordered="true" data-title="Buzzwords" data-moreinfo="# of times said around the office" data-myown="some random string"></div>

Google Analytics Events for li items

I'm trying to add Google Analytics click tracking events to li list items (active thumbnails) used in a responsive grid application, and can't get it working. I've researched here and in the Google developer forums without success. I'm sure there is something simple I'm doing wrong. I have the latest GA script code installed (page view analytics are working fine). Here is a code sample:
<ul>
<li data-type="link" data-url="http://www.dianagabaldon.com/books/outlander-series/" data-target="_self" >
</li>
<li data-thumbnail-path="outlander_files/thumbnails/outlanderbookseries1.png" ></li>
<li data-thumbnail-text >
<p class="largeLabel" >Diana Gabaldon - Outlander Series</p></li>
</ul>
Hope you can help. Feel free to suggest a better way of doing it.
Update: I'm still digging, and the GA code has been updated for Universal Analytics and looks like this:
<ul>
<li data-type="link" data-url="http://www.dianagabaldon.com/books/outlander-series/" data-target="_self" >
</li>
<li data-thumbnail-path="outlander_files/thumbnails/outlanderbookseries1.png" ></li>
<li data-thumbnail-text >
<p class="largeLabel" >Diana Gabaldon - Outlander Series</p></li>
</ul>
Update 2: I tried opening the outbound link target in a new page to see if a lack of callBack might be the problem. No success. Following are two views of the code, one with the contained inside the li with the outbound link, the other in a separate li with the same parent ul. Neither works. Does anyone know which syntax is correct? Thx.
Example 1: With href in it's own li:
<ul>
<li></li>
<li data-type="link" data-url="http://www.dianagabaldon.com/books/outlander-series/" data-target="_blank" ></li>
<li data-thumbnail-path="outlander_files/thumbnails/outlanderbookseries1.png" ></li>
<li data-thumbnail-text >
<p class="largeLabel" >Diana Gabaldon - Outlander Series</p></li>
</ul>
Example 2: With href inside outbound link li:
<ul>
<li data-type="link" data-url="http://www.starz.com/outlandercommunity/home.html" data-target="_blank" >
</li>
<li data-thumbnail-path="outlander_files/thumbnails/community1.png" ></li>
<li data-thumbnail-text >
<p class="largeLabel" >Starz: Outlander Community</p></li>
</ul>
The syntax you are using for the event tracking uses the classic GA syntax (_gaq.push), but if you are using Universal Analytics (assuming that is what you mean by using the "latest GA script code"), the syntax needs to be updated:
onClick="ga('send', 'event', 'GridLinks', 'Click', 'Outlander Clicks 1');"
I'm not familiar with Responsive Grid, but the likely explanation is that the call to ga only adds the event to a queue for asynchronous processing, and that the event is lost because the current document is immediately replaced afterwards (stopping the JavaScript execution for the current page). You would need to use a hit callback as described in the Google Analytics help, but I'm not sure how this would be integrated with Responsive Grid. Also note that there are a couple of other pitfalls you need to be aware of.

how laravel blade to merge request segment into url router in layout?

I'm develop in Laravel, with Router, Request, Blade (I think that's all related)
I need product filter menu at layout.blade.php
It does filter and menu like below
locations > east, west, south, north
category > shop, f&b, services
is_new > new, all
So then I make the the router as below
Route::get('/at/{location_id?}/{location?}/{category_id?}/{category?}/{is_new?}',array('as'=>'deals','uses'=>'HomeController#index'));
Current solution on my menu
I need a menu in layout.blade.php and generate url based on the user selected location, category, is_new. and this layout used for other actions as well.
I don't know how to do these logic on layout. and the solution I got at the end kinda trick.
<ul id='nav-category' class="dropdown-menu extended">
#if (Request::segment(1)=='deals')
#foreach (Deal::$categories as $category)
<li><a href='{{route("deals",array("location_id"=>Request::segment(3),"location"=>Request::segment(4),"category_id"=>$category["id"],"category"=>Str::slug($category["title"])))}}'>{{$category['title']}}</a></li>
#endforeach
#else
#foreach (Deal::$categories as $category)
<li><a href='{{route("deals",array("location_id"=>"all","category_id"=>$category["id"],"category"=>Str::slug($category["title"])))}}'>{{$category['title']}}</a></li>
#endforeach
#endif
</ul>
Problem
using Request::segment to get the state don't seem very right
may have more conditions come in and mess up the blade
This is should be a common problem, but somehow I can't find a good practice. Any suggestion?
For the parameters within the url you can use;
Route::current()->parameter('location_id|location|category_id');
Meaning your never limited to changing the url pattern within your routes, only limited to what you call the parameter you are passing.
With Request::segment(1)=='deals', there is no other way apart from;
#if(Request::is('deals/*'))
As this will check the pattern of the url to be anything starting with 'deals/'.

Joomla Registration form Fields Ordering

How do I order the fields on my joomla registration form?
As you can see, the captcha must be at the bottom:
http://www.celinasoft.com/index.php/component/users/?view=registration
First of all you will need to create your Registration view template override (to keep it Joomla update proof). To do so, create folder /templates/YOUT_TEMPLATE/html/com_users/registration and copy /components/com_users/views/registration/tmpl/default.php file there.
Then you will need to modify the code itself, open /templates/YOUT_TEMPLATE/html/com_users/registration/default.php file, you will see, that by default Joomla takes ALL fields from registration.xml file and just loops them through foreach cycle, this code:
<?php foreach ($this->form->getFieldsets() as $fieldset): ?>
...
...
<?php endforeach; ?>
You need to replace this cycle by your manual fields output like this:
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('email'); ?></div>
<div class="controls"><?php echo $this->form->getInput('email'); ?></div>
</div>
...
...
And output all desired registration fields like that, in order you prefer. Warning: don't forget that almost all of that fields are required for registration and cannot be missed.
You can find all field names in XML file components/com_users/models/forms/registration.xml
Please note that this is only sample code, to understand the logics. It haven't been tested live. So if errors occur - please let me know and we'll fix it :)
If anyone have a better/easier solution - I'd be happy to hear it.

Resources