blade

Using Laravel Form class to add the 'disabled' attribute

本秂侑毒 提交于 2019-12-03 22:16:53
Using Laravel 4's Form class, we can create a list using {{ @Form::select('colors', Colors::all()), $color }} Question: How can we add the attribute disabled using Blade without having to rewrite the clean Blade syntax into the usual ugly form? JustinHo Just add array('disabled') in the end like: {{ Form::select('colors', Colors::all(), $color, array('disabled')) }} This should do the work. {{ @Form::select('colors', Colors::all()), array( 'disabled' => 'disabled', 'class' => 'myclass' ) }} Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments

Laravel 4, view composers against @include

只愿长相守 提交于 2019-12-03 21:51:28
I noticed if I pass a second parameter to @include like this: @include('sidebars.pages', array('categories' => Category::all())) Then it is possible to replicate the concept of render partials within views and render partials within partials like in Rails. Do I still need view composers with this functionality? I appreciate any help! While that may be possible it's not the documented use of @include . I'd use caution when doing it like that, and personally, I wouldn't be calling a model within your view. Bind the data you require from your route or controller. Make use of a presenter to

Laravel 4 Blade Templating Engine with Conditional layout

馋奶兔 提交于 2019-12-03 21:48:54
I'm using L4 with Blade. I'd like to be able to conditionally extend a layout. For normal use, I'd like to extend the master layout, and for ajax renders, I'd like to be able to extend the ajax template. I use the following code: @if ( isset($ajax) ) @extends('layouts.ajax') @else @extends('layouts.master') @endif But when the page renders it just prints out @extend('layouts.master'). Does anyone know how to conditionally extend a layout or another? Thanks Try on the first line : @extends('layouts.' . isset($ajax) ? 'ajax' : 'master') EDIT You also can use it this way: @extends(((Request::ajax

Laravel 5 blade shows a blank page when there is error instead of throwing exception

拈花ヽ惹草 提交于 2019-12-03 21:31:34
In laravel 4 when you try to render a view that does not exists in app\views or a view with undefined variables laravel will throw an exception or show error that helps with debug. I have a fresh installation of laravel 5.0.13 and am having a tough time troubleshooting a blade template that shows a blank page when i render a view that does not exists instead or a template with undefined variables instead of throwing an exception or error which will clue me in when debug. I have installed filp/whoops:~1.0. but still recieve a blank page class ProfileController extends Controller { public

laravel - blade templates layout structure add row-fluid for each 4 spans

限于喜欢 提交于 2019-12-03 20:19:22
I have this blade template <div class="row-fluid"> @foreach($courses as $course) <div class="span3 learn"> Content </div> @endforeach Output <div class="row-fluid"> <div class="span3 learn"> Content </div> <div class="span3 learn"> Content </div> <div class="span3 learn"> Content </div> <div class="span3 learn"> Content </div> <!-- this span should be in a spearted row-fluid div --> <div class="span3 learn"> Content </div> </div> this code adds a block of span3 size I use Twitter bootstrap reponsive I need to add row-fluid for each 4 spans in the row-fluid div I want the output to be like this

Lumen: get URL parameter in a Blade view

喜夏-厌秋 提交于 2019-12-03 18:38:24
问题 I'm trying to get a url parameter from a view file. I have this url: http://locahost:8000/example?a=10 and a view file named example.blade.php . From the controller I can get the parameter a with $request->input('a') . Is there a way to get such parameter from the view (without having to pass it from the controller to the view)? 回答1: This works well: {{ app('request')->input('a') }} Where a is the url parameter. See more here: http://blog.netgloo.com/2015/07/17/lumen-getting-current-url

Need to check if an object is empty in laravel

六眼飞鱼酱① 提交于 2019-12-03 18:01:54
问题 I create a view by doing an eloquent query and then pass it over to Blade. @if($contacts != null) //display contacts @else You dont have contacts @endif However it always assume that $contacts has something even if the query gives me nothing. I did dd($contacts) and get: Collection {#247 ▼ #items: [] } How do I check if it is empty? 回答1: If it is a Eloquent Collection as it appears to be from your example you can use the isEmpty collection helper function; @if(!$contacts->isEmpty()) //display

Override section in a laravel blade template throwing undefined variable errors

梦想与她 提交于 2019-12-03 17:14:54
I am using Laravel 4 and blade templates, and running into an issue when I try and extend a template. In my layout I have @yield('content') and in my page I have @section('content') Welcome {{ $name }} @stop which works fine, I've created another page very similar to my first, and just want to change override the admin content section. The other sections in the template are fine. so I extend my page, and do @section('content') Hello! @stop I get an undefined notice with the $name variable. I tried @section('content') Hello! @overwrite and same deal, I get the notice error. I checked my

Can I use the Blade templating engine outside of Laravel?

我与影子孤独终老i 提交于 2019-12-03 17:05:05
问题 i'm want to creating a design pattern and use the "Blade templating engine". Can I use the Blade templating engine outside of Laravel and use it in my new pattern ? 回答1: For the record: I tested many libraries to run blade outside Laravel (that i don't use) and most are poor hacks of the original library that simply copied and pasted the code and removed some dependencies yet it retains a lot of dependencies of Laravel. So I created (for a project) an alternative for blade that its free (MIT

Add Class to select element on Laravel

给你一囗甜甜゛ 提交于 2019-12-03 15:30:28
I have this problem, I can't find the way to add class attribute in this Dropdown box {{Form::select('bancada', Bancada::lists('nombre','idBancada'))}} I have tried various syntax, but can not get it to work. Any suggestions? Thanks Use the forth parameter to add attributes to your element. {{Form::select('bancada', Bancada::lists('nombre','idBancada'), null, ['class' => 'my_class'])}} Take a look at the source ( $options is the same as attributes for your element). {{ Form::select('status', $statusList, null, array('class' => 'form-control')) }} In above example you can add class as fourth