blade

PHP code inside Laravel 5 Blade Template

丶灬走出姿态 提交于 2019-11-27 17:11:27
问题 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 ?? 回答1: According to documentation, in Laravel 5.2 and newer you can use the following code: @php {{-- php code here --}}

Laravel Blade views not showing the changes made to them

那年仲夏 提交于 2019-11-27 16:45:36
问题 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>

Laravel - Blade comments , blade rendering causing page to crash

回眸只為那壹抹淺笑 提交于 2019-11-27 12:17:18
问题 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') }}

Laravel-5 how to populate select box from database with id value and name value

折月煮酒 提交于 2019-11-27 11:12:24
I want to create a select box like the one below using illuminate\html : <select> <option value="$item->id">$item->name</option> <option value="$item->id">$item->name</option> </select> In my controller I tried this: public function create() { $items = Items::all(['id', 'name']); return view('prices.create', compact('id', 'items')); } And in my view this: <div class="form-group"> {!! Form::Label('item', 'Item:') !!} {!! Form::select('item_id', $items, null, ['class' => 'form-control']) !!} </div> The issue is that instead of $item->name is displaying all the info of the entity. Laravel

Laravel 5 call a model function in a blade view

白昼怎懂夜的黑 提交于 2019-11-27 10:34:27
问题 I want to build a blade view from 3 tables: "inputs_details" - fields: article_type (values: 'p' for product,'s' for service), article_id, .... "products" - fields: id, name "services" - fields: id, name But, in browser, I have the error: "Class 'Product' not found". Is there a solution to pass to the view this function (to find the name of the product or the service based on article_type and article_id)? I was trying also with join query, but I couldn't put so many conditions in a single

Blade: escaping text and allowing new lines

你离开我真会死。 提交于 2019-11-27 10:15:39
问题 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. 回答1: You can do the escaping first, using e() and then apply nl2br() : {{ nl2br(e($text)) }} e() is the function Blade uses when

Laravel Pagination links not including other GET parameters

て烟熏妆下的殇ゞ 提交于 2019-11-27 09:27:30
问题 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

Blade engine: print triple curly braces

流过昼夜 提交于 2019-11-27 06:42:28
问题 I know how to print double curly braces in Laravel: @{{ }} . But how can I print triple curly braces? My first thought of adding an @ before does not work, Laravel still tries to interpret it. Is there an easy way without encoding the braces to HTML entities? 回答1: This is the easiest way. Use HTML entities to escape curly braces. Tested in Laravel 5. See here for the list of HTML entities. HTML Entities Code {{ '{{{' . 'text'. '}}}' }} Output {{{text}}} 回答2: Update Very recently, a pull

Define the selected option with the old input in Laravel / Blade

狂风中的少年 提交于 2019-11-27 05:42:08
问题 I have this code: <select required="required" class="form-control" name="title"> <option></option> @foreach ($titles as $key => $val) @if (stristr($key, 'isGroup')) <optgroup label="{{ $val }}"> @else <option value="{{ $key }}">{{ $val }}</option> @endif @endforeach </select> So when the form have errors i use the line Redirect::route('xpto')->withInput()->withErrors($v) . But i can't re-populate the select fields. Any way to do this without using JavaScript for example? 回答1: Also, you can

How do I make global helper functions in laravel 5?

风流意气都作罢 提交于 2019-11-27 05:17:14
问题 If I wanted to make a currentUser() function for some oauth stuff I am doing where I can use it in a view or in a controller (think rails, where you do helper_method: current_user in the application controller). Everything I read states to create a helpers folder and add the function there and then that way you can do Helpers::functionName Is this the right way to do this? Whats the "laravel way" of creating helper functions that can be used in blade templates and controllers? 回答1: Create a