blade

PHP code inside Laravel 5 Blade Template

柔情痞子 提交于 2019-11-29 02:52:54
I have to place some PHP code inside Laravel 5 Blade Template. Like below @foreach ($farmer->tasks as $task) @if ($task->pivot->due_at) < date(now)) $style = 'alert alert-danger'; @elseif ($task->pivot->due_at) > date(now)) $style = 'alert alert-success'; @else $style = ''; @endif @endforeach Which is the actual procedure to place PHP code inside Laravel 5 Blade Template ?? user28864 According to documentation , in Laravel 5.2 and newer you can use the following code: @php {{-- php code here --}} @endphp Alternatively, you can extend the Blade templating engine as it's described here . If

Laravel Blade views not showing the changes made to them

本小妞迷上赌 提交于 2019-11-29 02:32:10
System Details : Using WAMP2.5 in Windows 64 bit MYSQL:5.6.17 PHP:5.5.12 Apache :2.4.9 I installed laravel via composer installation . It was all fine since recently all my views stopped showing any changes made to them . This is happening to views which use Blade template only. I have created the blade files correctly and named them with filename.blade.php . My view File Structure - views -layouts defaults.blade.php show.blade.php login.blade.php defaults.blade.php <!DOCTYPE html> <html> <head></head> <body> <div> <nav></nav> @yield('content') </div> @yield('footerscripts') </body> </html>

Laravel 4 blade drop-down list class attribute

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 23:47:14
问题 Laravel blade drop down list class attribute not working. I cannot find any reference to class or assigning attributes to select / drop-down lists in the documentation. http://www.laravel.com/docs/html#drop-down-lists Examples tried: {{ Form::select('product_id', $productList, array('class'=>'form-control')) }} {{ Form::select('product_id', $productList, $attributes = array('class'=>'form-control')) }} Both return the same html but without the class attribute: <select id="product_id" name=

Laravel 4 - Blade Templating - How to properly Link to Route?

£可爱£侵袭症+ 提交于 2019-11-28 22:43:57
I want to create a resourceful link with Laravel. Normally I just use the {{ link_to_route('Yadayadayada.route', 'LinkName', $params }} But in this case I am using a Template with this layout: <a href="index.html"> <i class="icon-dashboard"></i> <span class="menu-text"> Dashboard </span> </a> That means that inside the anchor tag, is as well a <i> -Tag and a <span> -Tag. Is it possible to use the {{ link_to_route }} -Method, without having to change the layout of the Template? Joseph Silber Use URL::route() to get just a link: <a href="{{ URL::route('user/profile/', $params) }}"> <i class=

Switch in Laravel 5 - Blade

纵然是瞬间 提交于 2019-11-28 20:59:33
How can I use switch in blade templates? When I used: @switch($login_error) @case(1) `E-mail` input is empty! @break @case(2) `Password` input is empty! @break @endswitch in result I see this text as plaintext. I prefer to use switch in few piece of code because it's more clean for me than when I using if. But if it's not possible just write it. Updated 2019 Answer Since Laravel 5.5 the @switch is built into the Blade. Use it as shown below. @switch($login_error) @case(1) <span> `E-mail` input is empty!</span> @break @case(2) <span>`Password` input is empty!</span> @break @default <span

How to echo a default value if value not set blade

夙愿已清 提交于 2019-11-28 19:31:46
问题 I would like to know what would be the best way to display a default value if the given value is not set. I have the following in a blade file (I can not guaranty that the key is set, it depends on a multitude of factors). {{ $foo['bar'] }} I would know if the following is the best way to go about it, {{ (isset($foo['bar']) ? $foo['bar'] : 'baz' }} or is there a better way to do this? Thanks :) 回答1: Use php's null coalesce operator: {{ $variable ?? "Default Message" }} Removed as of Laravel 5

Laravel - Blade comments , blade rendering causing page to crash

荒凉一梦 提交于 2019-11-28 19:27:36
I'm rendering a page that is primarily a form with view::make in Laravel and it is crashing, causing ERR_CONNECTION_RESET. After a long investigation and many red herrings, I started erasing (not commenting) random sections out of the blade file for the view and realized that if I a) erase 2 of the {{Form}} calls inside this section of the form b) remove the {{-- and --}} from around this section of the form {{-- <div class="form-row"> {{ Form::label('foo', 'foo:') }} {{ Form::text('foo') }} </div> <div class="form-row"> {{ Form::label('foo', 'foo:') }} {{ Form::text('foo') }} </div> <div

Blade: escaping text and allowing new lines

♀尐吖头ヾ 提交于 2019-11-28 17:12:05
I have a user-input text displayed on one of the pages. I want to allow new lines, though. How do I display the text, so it is escaped AND allows new lines ? I used nl2br() and Blade's tripple brackets {{{$text}}} , however, obviously, the tripple brackets escape <br/> tags as well. Is there a way to combine escaping and HTML's new lines using Blade? Thanks. You can do the escaping first, using e() and then apply nl2br() : {{ nl2br(e($text)) }} e() is the function Blade uses when compiling triple brackets You can use this {!! nl2br(e($text)) !!} 来源: https://stackoverflow.com/questions/28027236

Laravel Pagination links not including other GET parameters

强颜欢笑 提交于 2019-11-28 15:56:41
I am using Eloquent together with Laravel 4's Pagination class. Problem: When there are some GET parameters in the URL, eg: http://site.com/users?gender=female&body=hot , the pagination links produced only contain the page parameter and nothing else. Blade Template {{ $users->link() }} There's a ->append() function for this, but when we don't know how many of the GET parameters are there, how can we use append() to include the other GET parameters in the paginated links without a whole chunk of if code messing up our blade template? Alexandre Danault EDIT: Connor's comment with Mehdi's answer

laravel blade @include not working

让人想犯罪 __ 提交于 2019-11-28 13:56:59
I am trying to include files in my homepage using blade syntax :- @foreach($data as $articles) @include(app_path().$articles->path) <br /> @endforeach This is not working. The error says :- View [/var/www/blogproject/project/app/pages/articles/first-post.php] not found I even tried including just the first page :- @include(app_path().'/pages/articles/first-post.php') But the normal php include is working fine :- <?php include(app_path().'/pages/articles/first-post.php'); ?> Please help That's because that file is not in the app/views directory. When you call @include('filename') , Blade