blade

Laravel blade “old input or default variable”?

淺唱寂寞╮ 提交于 2019-12-05 08:41:05
问题 I want to show the old input in input value. If there isn't old input, than show other variable: value="{{ old('salary_' . $employee->id) or 'Default' }}" But when there is no old input, it gives me 1 instead of the default value! I think the problem has something to do with the concatenation, but I don't know how to fix it!? 回答1: or is a comparison operator in PHP, so your code is evaluating to true , or 1. What you want is a ternary if statement. As mentioned, or can be used in blade as

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

我只是一个虾纸丫 提交于 2019-12-05 06:48:21
问题 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

laravel blade include error - syntax error, unexpected

爷,独闯天下 提交于 2019-12-05 06:40:05
I'm using Laravel 4 locally with EasyPHP 14.1. I have created a route : Route::get('/test', function() { return View::make('test'); }); a layout (testlayout.blade.php) : <!doctype html> <html> <head> <title></title> </head> <body> <div class="container"> @yield('container') </div> </body> </html> and a view (test.blade.php) : @extends("testlayout") @section('container') <h1>Hello!</h1> @stop It works fine and I get "Hello!" But when a change my layout by adding an include like this : <!doctype html> <html> <head> <title></title> </head> <body> <div class="container"> @yield('container') </div>

Laravel 4 Blade Templating Engine with Conditional layout

三世轮回 提交于 2019-12-05 06:28:11
问题 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 回答1: Try on the first line :

Override section in a laravel blade template throwing undefined variable errors

青春壹個敷衍的年華 提交于 2019-12-05 03:15:31
问题 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

Conditional extends in Blade

孤人 提交于 2019-12-04 23:45:28
Is there any way to do a conditional @extends statement in the Blade templating language? What I've tried: @if(!Request::ajax()) @extends('dashboard.master') @section('content') @endif <div class="jumbotron"> Hey! </div> @if(!Request::ajax()) @stop @endif Output When the request was not AJAX it printed out @extends('dashboard.master') , but the AJAX request worked fine. What I'm trying to do Stop including the master template (which includes header and footer ) for AJAX so it can easily display the requested content itachi in the master layout: @if(!Request::ajax()) //the master layout with

how to add a dynamic image src with laravels blade

心已入冬 提交于 2019-12-04 21:36:49
问题 My question is very simple. i use blade in laravel to show the images like <img src="{{asset('assets/images/image.jpg')}}"> but what if my image is dynamic like: <img src="{{asset('assets/images/$imgsrc')}}"> i cant use <img src="{{asset('assets/images/{{ $imgsrc')}}"> because then i will end with: <img src="http://localhost/assets/images/{{ $imgsrc"> How can i call to a $variable in a blade {{}} call? 回答1: How about <img src="{{asset('assets/images/').'/'.$imgsrc}}"> EDIT when you need

Many-to-Many Eloquent relationship update with Laravel Form Model Binding & Checkboxes

亡梦爱人 提交于 2019-12-04 17:11:37
问题 I have 3 tables: doors id name image colors id name image door_colors id door_id color_id and 2 models with a many-to-many relationship (each door comes in a variety colors, and many colors overlap door-to-door): Door Model class Door extends Eloquent { public function colors() { return $this->belongsToMany('Color', 'door_colors'); } } Color Model class Color extends Eloquent { public function doors() { return $this->belongsToMany('Door', 'door_colors'); } } I want to create a form where I

Laravel blade compare two date

醉酒当歌 提交于 2019-12-04 12:15:05
I would like to compare 2 dates. So I create a condition like this in my template blade: @if(\Carbon\Carbon::parse($contrat->date_facturation)->format('d/m/Y') < $dateNow) <td class="danger"> {{ \Carbon\Carbon::parse($contrat->date_facturation)->format('d/m/Y') }} </td> @else <td> {{ \Carbon\Carbon::parse($contrat->date_facturation)->format('d/m/Y') }} </td> @endif My variable $dateNow has the same format on my value in $contract->date_facturation Screenshot It add a red background on the date 25/02/2018 while the date is not less than the variable $contract->date_facturation Do you have any

Blade view: if statement with OR/AND condition

假装没事ソ 提交于 2019-12-04 10:09:20
问题 Is it possible in Laravel 4.0 -blade-view to do an if statment like so? @if ($var1 === '1' OR $var2 === '1') //Do my stuff @endif Or @if ($var1 === '1' || $var2 === '1') //Do my stuff @endif Or whatever syntax it is. I didn't find anything in the L4 docs, does it exist ? 回答1: It should support all of your standard PHP operators, including || (logical OR). I have tested it myself and it works fine. Additionally, I would recommend simply testing this yourself in future to confirm it works/doesn