i'm displaying external Website Links from my Users in a Profile Page. The URL Format is: www.xyz.com. When i put a http:// before the {{ url }} Laravel changes the Protocoll automatically to https://. In the Result a lot of the Websites don't open properly. I set the APP_URL in the .env File to
https://domain because i want to use SSL in the App.
Laravel (Blade) is removing the http:// from the URL when i just want to print the Variable too. Even when i put http:// right in front the URL in the DB (MySQL) i still have the same problem.
All i do in the Controller is:
$user = \App\User::find($id);
After 2 days of research i'm reaching out to the community. Basically i'm searching for something like secure_url() inverse.
What i tried:
{{ url('http://'.$url) }}
{!! url('http://'.$url) !!}
{!! url(e('http://'.$url)) !!}
<a href="http://{{ $url }}">
{{ $url }}
Putting the Protocoll right in the DB
What do i not get here? Thank you for any help.
EDIT
Laravel does this only when i visit my site over https.
UPDATE & SOLUTION
It was the problem of the Laravel Cache Speed Package. I deactivated it and everything was back to normal. My fault, my bad.
Related
I'm building the mobile application of my laravel project for the profile part {{ __('main.nav_profile') }} This is how I do the redirect. But android button redirect asks for URL and so redirection fails. How can I solve this.
Picture : https://www.hizliresim.com/ml27x74
For example, there is no problem with others.
site.com/favorites and site.com/settings/edit
{{ __('main.nav_saved') }}
<div class="dropdown-divider"></div>
{{ __('main.nav_account') }}
I had read somewhere the the Laravel helper functions route() and url() would match the protocol of the current page. This has not been my experience and I cannot find a way to do it cleanly.
<!-- https://domain.com/public/route1 -->
<a href='{{ route('route2') }}'> domain.com/route2 </a>
404 due to lack of "/public/" and no https
<a href='{{ url('/route2') }}'> domain.com/public/route2 </a>
proper path but still drops https
<a href='{{ secure_url('/route2') }}> https://domain.com/public/route2 </a>
proper path and protocol but is explicit
Is there a way to do what I want? It seems absurd to me that these helpers would be unable to accomplish something this simple. Something that the following line of code does with no tricks (its downside being the obvious loss of benefits associated with using helper functions [UPDATE: in particular having everything break when running locally due to a different app path]):
<a href='/public/route2'> https://domain.com/public/route2 </a>
To further convolute things I would like to add that when running on localhost, the first version {{ route('route2') }} produces a path that includes /public/, though it is possible that I have a different config file somewhere on the server (this is a very large project). Bonus points if someone can point me in the right direction for that issue as well.
routes.php:
Route::group(array('prefix' => 'route2' ), function(){
Route::get('/', array(
'as' => 'route2',
function(){
return View::make('pages.route2');
}
));
...
});
Thank you kind souls!
UPDATE:
I have continued searching and been unable to find any relevant information regarding Helper function url generation. It seems the majority of info with similar keywords is about forcing HTTPS site-wide (server config) or setting up redirects. It just seems so much simpler to generate the correct link in the first place. Plain HTML can do it, so should Laravel.
UPDATE 2:
Using the asset helper seems to work how I would expect url to. Please someone tell me this hack is not my only option...
I created pagination by writing
$users = User::paginate(25);
Then to display the links, I used the following command,
{!! $users->render() !!}
As the command given below no longer works in Laravel 5
{{$users->links()}}
{!! $users->render() !!} displays the pagination links in the view but there is a slight issue with the links.
This link it generates is like this
http://localhost/laravel/public/users/?page=2
How can I change the generated link to something like this
http://localhost/laravel/public/users?page=2
i.e to remove the slash(/) after users in the url?
The reason for this is that the url with slash after users fails.
Any help regarding pagination will be greatly appreciated.
Thanks
Please try the following $users->setPath('')->render();. I had a similar situation and this fixed the issue for me.
I just installed an SSL cert onto my web server and I'm having some issues with my laravel setup.
I'm using
{{ HTML::style('css/style.css') }}
to include css and for js
{{ HTML::script('js/jquery.js') }}
Though when I load the page with https it seems to include the 2 with http instead of https.
Any idea why?
I had an issue with this too. My SSL is redirecting fine, but the CSS and JS links generated by {{ HTML::style('css/style.css') }} and HTML::script('js/script.js') were linking to the http versions.
If you look at the Illuminate\Html\HtmlBuilder Documentation you'll see that you can specify the secure version as follows:
{{ HTML::style('css/style.css', array(), true) }}
{{ HTML::script('js/script.js', array(), true) }}
true means $secure flag is on.
This might help.
In short you need to add a App:before in the app/filters.php.
In my web app if a user is logged in and clicks on the logo, instead of going to the entry page as an anonymous user, I would load their member homepage URL instead.
How it works is when a user joins or logs in, I generate this route $this->generateUrl('member_page'), array('member' => $member->getName()));
and my route is configured as so,
member_page: pattern: /member/{member}/
defaults: { _controller: HomeBundle:Default:member }
and it generates this url:
http://website.com/member/John+joe/
The problem is, when I recall the route it just shows this url
http://website.com/member/
I have tried calling a new action and using $request->getURI() but it does not maintain the dynamic get parameters.
I'm trying to avoid a call to the DB to get the user name each time the click the logo.
Any help would be great, thanks!
A few weeks ago, I had to do something quite similar and inspired myself from the PagerFantaBundle. Have you tried this code in your controller:
$request = $this->getRequest();
return $this->redirect($this->generateUrl($request->get('_route'), $request->query->all()));
Instead of using the username you could use the user ID which will be saved into the users session after log in. This will also avoid any conflicts with users who have the same name.
One of possible solutions would be to generate proper routes right in Twig:
{% if app.user %}
<a href="{{ path('member_page', {'member': app.user.name}) }}">
{% else %}
<a href="{{ path('your_homepage') }}">
{% endif %}
<img src="yourlogo.png" />
</a>