blade

Truncate string in Laravel blade templates

谁说我不能喝 提交于 2019-11-27 05:13:20
问题 Is there a truncate modifier for the blade templates in Laravel, pretty much like Smarty? I know I could just write out the actual php in the template but i'm looking for something a little nicer to write (let's not get into the whole PHP is a templating engine debate). So for example i'm looking for something like: {{ $myVariable|truncate:"10":"..." }} I know I could use something like Twig via composer but I'm hoping for built in functionality in Laravel itself. If not is it possible to

How to include a sub-view in Blade templates?

戏子无情 提交于 2019-11-27 04:35:07
I am trying to set up a site using laravel, but I'm really having trouble with basic things that the documentation just doesn't cover. In this case, I see that it says I can include one view inside another by using @include('view.name') . What is view.name? Where is it saved? I tried creating a file app/views/view.name.blade.php , but it wasn't read. How does the file name map to the blade name? winkbrace EDIT: Below was the preferred solution in 2014. Nowadays you should use @include , as mentioned in the other answer . In Laravel views the dot is used as folder separator. So for example I

Where to place Blade::extend

别等时光非礼了梦想. 提交于 2019-11-27 04:29:53
问题 I want to add the following code to my laravel project to support the break and continue statements in blade. This is the code: Blade::extend(function($value) { return preg_replace('/(\s*)@(break|continue)(\s*)/', '$1<?php $2; ?>$3', $value); }); I have no idea however where to place it, any help would be appreciated? 回答1: There's no requirement telling you where you should put the code, you could even put it in your routes.php (which is a bit messy of course). You only have to make sure that

Laravel: How do I parse this json data in view blade?

会有一股神秘感。 提交于 2019-11-27 04:00:43
Currently this is my view {{ $leads }} And this is the output {"error":false,"member":[{"id":"1","firstName":"first","lastName":"last","phoneNumber":"0987654321","email":"email@yahoo.com","owner":{ "id":"10","firstName":"first","lastName":"last"}}]} I wanted to display something like this Member ID: 1 Firstname: First Lastname: Last Phone: 0987654321 Owner ID: 10 Firstname: First Lastname: Last It's pretty easy. First of all send to the view decoded variable (see Laravel Views ): view('your-view')->with('leads', json_decode($leads, true)); Then just use common blade constructions (see Laravel

How do I disable Laravel view cache?

家住魔仙堡 提交于 2019-11-27 00:56:13
问题 I have an exception in one of my views. However, instead of telling me the name of the view so I can find it and fix it, laravel says it is in app/storage/views/110a3ecc0aa5ab7e6f7f50ef35a67a8b , which is meaningless. How do I disable this view caching, so that laravel uses and refers to the actual files? 回答1: Out of the box? You can't. But you can extend the BladeCompiler class, overriding the method resposible for checking if the view has been expired: class MyBladeCompiler extends

How to include a sub-view in Blade templates?

天涯浪子 提交于 2019-11-26 22:15:13
问题 I am trying to set up a site using laravel, but I'm really having trouble with basic things that the documentation just doesn't cover. In this case, I see that it says I can include one view inside another by using @include('view.name') . What is view.name? Where is it saved? I tried creating a file app/views/view.name.blade.php , but it wasn't read. How does the file name map to the blade name? 回答1: EDIT: Below was the preferred solution in 2014. Nowadays you should use @include , as

Laravel stylesheets and javascript don't load for non-base routes

删除回忆录丶 提交于 2019-11-26 18:24:25
Okay--I know this is a really elementary issue, but I can't figure it out. This is a question regarding Laravel. Basically, I have my stylesheets embedded in my default layout view. I'm currently just using regular css to link them, such as: <link rel="stylesheet" href="css/app.css" /> It works great when I am at a single level route such as /about , but stops working when I go deeper, such as /about/me . If I look at Chrome's developer console I see some of the following errors (only for the deeper routes): Resource interpreted as Stylesheet but transferred with MIME type text/html: "http:/

Laravel 5 - global Blade view variable available in all templates

时光怂恿深爱的人放手 提交于 2019-11-26 16:07:41
How can I in Laravel 5 make global variable which will be available in all Blade templates? Digitlimit Option 1: You can use view::share() like so: <?php namespace App\Http\Controllers; use View; //You can create a BaseController: class BaseController extends Controller { public $variable1 = "I am Data"; public function __construct() { $variable2 = "I am Data 2"; View::share ( 'variable1', $this->variable1 ); View::share ( 'variable2', $variable2 ); View::share ( 'variable3', 'I am Data 3' ); View::share ( 'variable4', ['name'=>'Franky','address'=>'Mars'] ); } } class HomeController extends

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

烂漫一生 提交于 2019-11-26 15:27:25
问题 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']) !!} <

Laravel: How do I parse this json data in view blade?

烈酒焚心 提交于 2019-11-26 10:59:24
问题 Currently this is my view {{ $leads }} And this is the output {\"error\":false,\"member\":[{\"id\":\"1\",\"firstName\":\"first\",\"lastName\":\"last\",\"phoneNumber\":\"0987654321\",\"email\":\"email@yahoo.com\",\"owner\":{ \"id\":\"10\",\"firstName\":\"first\",\"lastName\":\"last\"}}]} I wanted to display something like this Member ID: 1 Firstname: First Lastname: Last Phone: 0987654321 Owner ID: 10 Firstname: First Lastname: Last 回答1: It's pretty easy. First of all send to the view decoded