How to the domain url in laravel5 - laravel

I have to get the domain url (ex. http://www.example.com/) in laravel blade. I've tried using {{ url() }} but it returns the path to my public directory. Is there any one line function to get this? How do I get the domain in blade? Need help. Thanks.

You can also try
{{ Request::server ("SERVER_NAME") }}
{{ Request::server ("SERVER_NAME") }}
Or go with
{{ Request::root() }}

Related

Don't show get parameter in blade

In My route:
Route::get('/item/{itemId?}', 'ItemController#index');
Controller returning to:
http://example.com/item/12
But in blade don't showed {{Request::segment(3);}}
Please, help! And sorry for my English
It should be segment(2):
{{ Request::segment(2) }}
And segment(1) will return "item"
Your route has 2 segments! so if you need id it's in segment2
{{ Request::segment(2) }}
segment 1 will be equal to items
{{ Request::segment(1) }} //items

Laravel blade creating url

I have a simple problem, basically I am getting name of the website from database and create a link according to it's name. it looks like:
#foreach ($websites as $website)
<a class="websites" href=" {{ asset ($website->name )}}"> {{ asset ($website->name )}}
</a>
#endforeach
Which gives for example: http://localhost/name
Howver links needs to be like this:
http://localhost/website/name how can I add /website into my URL using blade template in laravel?
Try this:
{{ url('website/' . $website->name) }}
This have some improvement on #Laran answer regarding best practices.
You would better use url parameters instead of concatenating the $name parameter
{{ url('website', [$name]) }}
And using named routes will be better to decouple the routing from the views.
// routes/web.php
Route::get('website')->name('website');
and write inside your {{ route('website', [$name]) }}

How to add helper class function in twig template with laravel

in blade template I have used like:
{{ Helper::getName() }}
But how it is used with twig template?
If you are using laravel-twigbridge you can use helpers from default Extensions, e.g:
{{ form_open(...) }}
instead of
{{ Form::open(...) }}
See docs

Get image name from database in laravel

I have database, with columns image and alttag. I want to use them in laravel blade view. I try something like this:
{{ HTML::image('images/{{ $item->image }}', $alt="{{ $item->alttag }}") }}
But syntax isn't correct. If i just echo image and alttag like this:
<h1>{{ $item->alttag }}</h1>
then they are correct. I wonder what is wrong in my code.
You used blade syntax in a PHP string. Watch the compiled blade templates to see where you did go wrong.
In short. Try this:
{{ HTML::image('images/'. $item->image, $alt = $item->alttag) }}
or equally short:
{{ HTML::image("images/{$item->image}", $alt = $item->alttag) }}

Using HTML Placeholder in Laravel 4

{{ Form::text('username', Input::old('username')) }}
This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.
I tried to use the example
{{ Form::text('username', 'Username', Input::old('username')) }}
But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username')) }}
This works for Laravel 4!!
{{ Form::text('username', null, array('placeholder'=>'Username' )); }}
Use:
{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}
Been a while since this was updated but with Former for Laravel the way to do this would be:
Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
The lang file would be called langfile.php with the array containing:
<?php
return array (
'path.to.placeholder.text' => 'Some Placeholder Text.'
);
In case somebody wonders how this should work for a password field:
{{ Form::password('password', array('placeholder'=>'Password')) }}

Resources