how to get current route name in blade file laravel 5.6 - javascript

I want to reload my current page with onclick function, for this how to get my current route name in blade file.
This is my code:
<li class="dropdown user user-menu" onclick="window.location='{{ Route::current() }}'" style="cursor: pointer;">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="livicon" data-name="refresh" data-loop="true" data-color="#42aaca"
data-hovercolor="#42aaca" data-size="28"></i>
</a>
</li>
What is the best way to get the current route?
I want to use it on function onclick.

With Below code you can know more about your current route.
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
Reference : Link
Hope it will help!

Best way to get current url in Laravel blade:
onclick="window.location='{{ Request::url() }}'"

You can reload current page like this:
onclick="window.location.reload()"
There is no need to set current route in blade it's possible with javascript abilities.

Related

Indirectly changing UI by storing data in a class variable not working

If I want any changes in my UI then I direct pass the data like;
In HTML Template
<li *ngFor="let post of posts;let i = index;">
{{i+1}}) {{post.name}}
<button (click)="editCategory(post)" class="btn btn-danger btn-sm">Edit</button>
</li>
In Component TS
editCategory(post){
post.name="Something";
}
this will reflect in the UI too and works fine!
but when I try to do it indirectly that doesn't happen like:
In HTML Template
<li *ngFor="let post of posts;let i = index;">
{{i+1}}) {{post.name}}
<button (click)="deleteCategory(post); modal1.show();" class="btn btn-danger btn-sm">Edit</button>
</li>
<div #modal1="bs-modal">
<button (click)="finallyDeleteCategory(); modal1.show();" class="btn btn-danger btn-sm">Edit</button> //making changes through this button
</div>
In Component TS
deleteCategory(post){
this.savedPost=post;
}
finallyDeleteCategory(){
this.savedPost.name="deleted"; //this Doesn't work
}
While am saving data in the class variable then making changes in the variable then it is not reflecting in the UI.
Doubts:
How can i save the refernce of the Post in the class variable?
Is this the correct way to make changes indirectly or i have pass on data in the html itself?
Any help would be great thanks!
Since finallyDeleteCategory is outside the loop context you cant just pass a reference of post and change its name since it does not exist.
this.savedPost.name="deleted"; does not work because the element being looped are part of the posts array.What you can do is save the post index i instead of the post object and in the method
(click)="editCategory(i)"
deleteCategory(loopindex){
this.index=loopindex
}
finallyDeleteCategory you retrieve the posts from the array then change it directly there.
finallyDeleteCategory(){
posts[this.index].name="deleted";
}
It seems you only save the deleted post when you call the 'deleteCategory' method on the list item. So with your setup, the changes will only reflect when you first press the edit button on one of the list items.

difference between using ui-sref and href(where to use) in ionic framework using ui-router service

I am working on ionic framework. So I am confused with using ui-sref and href. For example for tabs we use ui-sref as we can have various states all linked to some main (base) url.
eg
.state('dashboard', {
url: "/dashboard",
templateUrl: 'templates/dashboard.html',
controller: 'dashboardCtrl'
})
.state('dashboard.active', {
url: '/active',
views: {
'active': {
templateUrl: 'templates/active.html',
controller: 'ActiveCtrl'
}
}
})
My dashboard page has tabs whish have various various states now if I want to move to a diffrent template from one of these states or templates (eg to active.html)
eg.
//active.html
<li class="item">
<a class="button button-positive" ui-sref="dashboard.editClaim"> Edit Claim
</a>
</li>
or
<li class="item">
<a class="button button-positive" href="#/dashboard/editClaim"> Edit Claim
</a>
</li>
here should i use ui-sref or href.
Also editclaim template has tabs should i use ui-sref there and will it work fine because currently that is the problem.
So I am wondering if I have to maintain some state till there. Thank you.
here should i use ui-sref or href.
From docs: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
A directive that binds a link ( tag) to a state. If the state has
an associated URL, the directive will automatically generate & update
the href attribute via the $state.href() method. Clicking the link
will trigger a state transition with optional parameters. Also
middle-clicking, right-clicking, and ctrl-clicking on the link will be
handled natively by the browser.
<a ui-sref="home">Home</a> is converted to:
Home
Use ui-sref if you decided to use ui-router. This is a best practice. You can change in your code associated URL for the same state and you don't need to maintain your links.
Developers rarely use href for example in big lists for better performance to avoid additional watchers, but hope its not your case
<a class="button button-positive" ui-sref="dashboard.editClaim"> Edit Claim
</a>
is going to get convert in:
<a class="button button-positive" href="#/dashboard/editClaim"> Edit Claim
</a>
in your browser since ui-sref is just a simple directive provided by angular. For more info:
https://scotch.io/tutorials/3-simple-tips-for-using-ui-router
What's next? You should use ui-sref when using ui-router

Routing not working in angular web app

I'm trying to route to a reset page from the login page of the webapp i'm working on but nothing happens when I click on "forgot Password". when I replace #/login with #/reset in the address bar the view changes to the reset page so I know the route is setup correctly. Any idea what i'm doing wrong?
My code:
in my login template:
<a href="#" class="forgotPassword" ng-click="forgotPassword()">Forgot Password?
In my login controller:
$scope.forgotPassword = function(){
$location.path('/reset');
}
whenever using anchor tag and want to redirect by using ng-click, do not use href
for you remove the href
now your template look like this..
<a class="forgotPassword" ng-click="forgotPassword()">Forgot Password?
Have you tried to redirect your view with the "href" tag instead of the "ng-click" function?
Forgot Password?

Iron Router - window.location.href gets href of previous page

i am working on an app with Meteor that requires social shares. So I want to implement a social share on the single-post page.
I so I have this registered helper for facebook share:
Template.registerHelper('shareOnFacebookLink', function() {
return 'https://www.facebook.com/sharer/sharer.php?&u=' + window.location.href;
});
and in the template, I have this :
<a href="{{shareOnFacebookLink}}" target="_blank" class="btn btn-facebook">
<i class="fa fa-facebook"></i>
</a>
The problem is that when i navigate from the homepage to the single-post (where the registered helper is needed), the window.location.href still shows the href of the previous page until I reload the the single-post page.
What i want is how can I make the window.location.href get the href of the single-question page as soon as I land on it without having to refresh it?
Thanks all
You can try to use Meteor.Router.path() to get your current path.

template is not loading in angularjs?

iam working on angulatjs uirouter.The code contains 2 states say home and new and when i click on any of these links the state & url changess.But the problem is the template corresponding to those state is not loading.
here is my code
var app=angular.module("myApp",['restangular','ui.router']);
app.config(['RestangularProvider',function(RestangularProvider){
RestangularProvider.setBaseUrl('http://localhost:9999')
}])
app.config(['$stateProvider',function($stateProvider){
$stateProvider.
state('home',{
url:'/home',
templateUrl:'/view/home.html'
})
.state('next',{
url:'new',
templateUrl:'/view/new.html'
})
}])
html
<a ui-sref='home'>
home
</a>
<a ui-sref='next'>
new
</a>
i don't know what the problem is? can anyone help me?..
It seems that you missed the ui-view in order to let the template get plugged in
<a ui-sref='home'>
home
</a>
<a ui-sref='next'>
new
</a>
<div ui-view></div>

Categories

Resources