laravel-blade

Find last iteration of foreach loop in laravel blade

泄露秘密 提交于 2019-12-05 09:47:26
问题 In blade template i use last() method to find last iteration of foreach loop: @foreach ($colors as $k => $v) <option value={!! $v->id !!} {{ $colors->last()->id==$v->id ? 'selected':'' }} > {!! $v->name !!} </option> @endforeach Is it ok? Perhaps there is a Laravel-style way to do the same? 回答1: As for Laravel 5.3+, you can use the $loop variable $loop->last @foreach ($colors as $k => $v) @if($loop->last) // at last loop, code here @endif @endforeach 回答2: What you do is absolutely fine if you

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

Allow admin users to see what other user type can see/do?

淺唱寂寞╮ 提交于 2019-12-04 16:48:13
I have a Laravel web application consist of 2 types of user: customer admin Base on their user type , they can see, and perform different things. Customer When log-in as customer, my customer will see different dashboard. Admin When log-in as admin, I can see a list of users in a table Example, userA userB userC more … Goal: I want to see what customer see when click on one of the user on the list. I couldn’t come up the solution for that. IMO Will Auth::user()->type work for this scenario ? The goal is to render the page as Auth:user()->type == ‘customer’ , when the actual Auth::user()->type

How to comment code in a vue.js file?

夙愿已清 提交于 2019-12-04 09:51:16
问题 I have the need to insert a comment inside a vue.js file for future references, but I don't find how you do this in the docs. I have tried // , /**/ , {{-- --}} , and {# #} , but none of them seem to work. I am using Laravel's blade. So this is the sample_file.vue : <template> <div class="media"> <like-button :post="post" v-if="post.likedByCurrentUser === false && "></like-button> {{--I want to comment this but I get an error from the gulp watch: post.canBeLikedByCurrentUser === true--}} <div

Laravel Blade : What does it mean the double column in parameter in @extends('adminlte::page')

邮差的信 提交于 2019-12-04 05:24:40
问题 I want to use this Admin Panel : https://github.com/jeroennoten/Laravel-AdminLTE But i don't understand this syntax : @extends('adminlte::page') . The page is a view but what does it mean to add adminlte and the double column in this example ? I have never seen this syntax, and i didn't find about it in the Laravel blade docs, can anyone enlighten me please ? 回答1: This is used to identify the package from which the view should be loaded from. For example you have a package named neokyuubi

Pass multiple parameters to a blade directive

為{幸葍}努か 提交于 2019-12-04 03:29:55
I'm trying to create a blade directive to highlight some words that will return from my search query. This is my blade directive: class AppServiceProvider extends ServiceProvider { public function boot() { Blade::directive('highlight', function($expression, $string){ $expressionValues = preg_split('/\s+/', $expression); foreach ($expressionValues as $value) { $string = str_replace($value, "<b>".$value."</b>", $string); } return "<?php echo {$string}; ?>"; }); } public function register() { } } And I call in blade like this: @highlight('ho', 'house') But, this erros is following me: Missing

Laravel Blade - Chain/Embed multiple layouts

孤街醉人 提交于 2019-12-04 00:17:26
In my favorite templating frameworks they typically have the ability to nest layouts. Is this something that is possible in Blade? For example... master.blade.php <html> <head><!-- stuff --></head> <body> @yield('content') </body> </html> nav.blade.php @extend('master') <nav> <!-- nav content --> </nav> @yeild('content') breadcrumb.blade.php @extend('nav') <breadcrumb> <!-- breadcrumb content --> </breadcrumb> @yield('content') home.blade.php @extend('nav') @section('content') <home> <!-- content --> </home> @endsection about.blade.php @extend('breadcrumb') @section('content') <about> <!--

Laravel Blade html image

◇◆丶佛笑我妖孽 提交于 2019-12-03 23:29:15
问题 My image file path is public/img/logo.png and my app.blade.php file path is resources/views/app.blade.php Inside of my app.blade.php file I use {{HTML::image('/img/stuvi-logo.png')}} to display an image. I don't understand why this won't find the image. What is the root folder of the image() method? 回答1: Change /img/stuvi-logo.png to img/stuvi-logo.png {{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }} Which produces the following HTML . <img src="http://your

Check if a view exists and do an @include in Laravel Blade

只谈情不闲聊 提交于 2019-12-03 13:03:32
With Laravel Blade, is there an elegant way to check if a view exists before doing an @include ? For example I'm currently doing this: @if(View::exists('some-view')) @include('some-view') @endif Which gets quite cumbersome when 'some-view' is a long string with variables inside. Ideally I'm looking for something like this: @includeifexists('some-view') Or to make @include just output an empty string if the view doesn't exist. As an aside, I would also like to provide a set of views and the first one that exists is used, e.g.: @includefirstthatexists(['first-view', 'second-view', 'third-view'])

laravel 5.2 How to get route parameter in blade?

筅森魡賤 提交于 2019-12-03 10:48:30
问题 this is my url http://project.dev/blogs/image-with-article so, here I need the parameter image-with-article in my blade to display which is a parameter named slug here is in my routes file I need the slug paramter in blade. Route::get('/blogs/{slug}', ['as'=>'blog.by.slug', 'uses'=> 'CmsController@show']); 回答1: I'm not sure what you mean. If you're trying to construct the route in a Blade template, use <a href="{{ route('blog.by.slug', ['slug' => 'someslug']) }}">...</a> If you're trying to