blade

Laravel Blade without extra whitespace?

让人想犯罪 __ 提交于 2020-01-29 06:49:11
问题 If you do this you get an error: <p>@if($foo)@if($bar)test@endif@endif</p> And if you do this, you get <p> test </p> , adding too much whitepace: <p>@if($foo) @if($bar)test@endif @endif</p> Is there a way to avoid this? Edit: see my answer below for an updated response. There's a clean way to do this with no hacks or external libraries. 回答1: Try with a ternary operator, there is no whitespace control in Laravel <p>{{ $foo ? ($bar ? 'test' : '') : ''}}</p> 回答2: You could always use the

Laravel. Keep variable in view during all routes

ぃ、小莉子 提交于 2020-01-25 04:05:28
问题 I got pretty simple problem in laravel 4.2 but i can't solve it. I got included right-side-bar which must contain some content from my database table during all routes. I got mysql query on home page route and I pass variable to view: $query.... return View::make('home')->with('query', $query); All I want is to send this vatiable to included view 'right-side-bar', but it has to recognize it during all routes. I tried nesting, sharing variable, but since routes change, my 'right-side-bar' view

Laravel blade global variable

别说谁变了你拦得住时间么 提交于 2020-01-23 03:04:07
问题 I have a problem in global variables in laravel. I know about view composer and my question is not related to that subject. How can I do such a simple thing in laravel view (*.blade.php | .php) template engine? for example this is a sample code from one of my views ( .blade.php | *.php): <?php function myFunc() { global $myvar; if ( ! $myvar ) { $myvar = 'my var is empty'; } dd( $myvar ); } $myvar = 'my var value'; myFunc(); At the end of the execution it shows up 'my var is empty' and not

Caching View Output in Laravel 4

放肆的年华 提交于 2020-01-22 04:32:05
问题 I know that Blade already caches the compiled PHP for all blade views, but I would like to take this a step further. A website that I'm working on is modularized into component views and then pieced together in the default controller. Each of the "widgets" has its own view, which rarely changes content (with the exception of a few frequently updating ones). So, I'd like to cache the HTML output of these rarely-changing views to prevent them from being evaluated on every page load. In Laravel

How can display space in view blade laravel 5.3?

本秂侑毒 提交于 2020-01-17 04:44:06
问题 My records in db is like this : I want to display with space I try like this : {{ nl2br($text) }} and {{ nl2br(e($text)) }} It does not work How can I solve it? 回答1: have you tried using {!! !!} here you can use HTML entity &nbsp 回答2: you can create a helper like this $output = nl2br(str_replace(" ", " &nbsp;", $db_record)); Then your blade file {!! $output !!}; 来源: https://stackoverflow.com/questions/43714169/how-can-display-space-in-view-blade-laravel-5-3

Laravel 5.2 - Method links does not exist

浪子不回头ぞ 提交于 2020-01-14 19:37:25
问题 i'm passing my array $posts to my view and i'm tryng use pagination but i have the error: Method links does not exist. (View: C:\xampp\htdocs\app\resources\views\search.blade.php) CONTROLLER $posts = Post::where('visible', 1) ->where('expire_date', '>', $current)->where('delete', 0); $posts->paginate(1); $posts = $posts->get(); return view('search', compact('posts')); VIEW <div class="pagination-bar text-center"> {{ $posts->links() }} </div> 回答1: Change you code to this: $posts = Post::where(

Laravel: How to redirect after controller method execution

旧城冷巷雨未停 提交于 2020-01-14 14:12:39
问题 web.php : Route::post('caption/{id}/delete', 'DetailController@deleteCaption'); DetailController.php : public function deleteCaption(Request $request, $id) { $caption = Caption::findOrFail($id); $caption->delete(); //doesn't delete permanently return response(204); } admin.blade.php : <p value='{{$caption->id}}'>{{$caption->content}}</p> <form action="caption/{{$caption->id}}/delete" method="post"> <button type="submit">Delete caption</button> </form> <form action="caption/{{$caption->id}}

Laravel: How to redirect after controller method execution

一笑奈何 提交于 2020-01-14 14:11:17
问题 web.php : Route::post('caption/{id}/delete', 'DetailController@deleteCaption'); DetailController.php : public function deleteCaption(Request $request, $id) { $caption = Caption::findOrFail($id); $caption->delete(); //doesn't delete permanently return response(204); } admin.blade.php : <p value='{{$caption->id}}'>{{$caption->content}}</p> <form action="caption/{{$caption->id}}/delete" method="post"> <button type="submit">Delete caption</button> </form> <form action="caption/{{$caption->id}}

Let users create custom blade layouts / store in database

Deadly 提交于 2020-01-14 05:28:26
问题 Problem : I need to let my web-app users create their own blade layout templates . So the most convenient solution is to store the blade templates into the database. However, I see no method to extend a child view from a layout code NOT SPECIFIED in a blade file . Furthermore the next concern is security. I can't rely on users to insert safe code . Giving access to insert php code or directly blade code is disastrous for the system. So how to? Save the layout template in database Make sure no

laravel基础学习笔记记录(5)---url生成

試著忘記壹切 提交于 2020-01-07 15:55:48
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 路由写法: 文件路径:aravel\app\Http\routes.php Route::get('student/urlTest',['as'=>'url','uses'=>'StudentController@urlTest']); blade视图写法 文件路径:laravel\resources\views\ <!-- url --> <!-- 原始路径 --> <a href="{{url('student/urlTest')}}">url()</a><br/> <!-- 接口路径 --> <a href="{{action('StudentController@urlTest')}}">action()</a><br/> <!-- 别名路径 --> <a href="{{route('url')}}">route()</a><br/> 来源: oschina 链接: https://my.oschina.net/lixiaoting/blog/3154392