Laravel 5 Blade Mystery - laravel

I am having a curious blade problem.
I have an edit blade that is rendering, but not with the master blade. Debugbar shows that both views (master and delete) are being shown. They are not!
Other blades used in conjunction with master all work. I tried duplicating those blades and inserting the specific data to no avail.
I have cleared history in the browser and done php artisan cache:clear. Nothing.
Master Blade is working for all other renderings. Here is detail:
<div class="intro">
<section>
#yield('intro')
</section>
</div>
This blade works and is rendered with the master:
#extends('layouts.master')
#section('title')
Your Profile
#stop
#section('head')
#stop
#section('intro')
<div class="output">
<h2>Your Pets</h2>
<div>
</div>
#if(sizeof($pets) == 0)
No pets
#else
#foreach($pets as $pet)
<div class="p1">
<h3>{{ $pet->petName }}</h3>
<p><img src='{{ $pet->photo }}' width="200px" height="200px"></p>
<p>{{ $pet->breed }}</p>
<a href='/profile/edit/{{$pet->id}}'>Edit</a> |
<a href='/profile/confirm-delete/{{$pet->id}}'>Delete</a>
</div>
#endforeach
#endif
</div>
#stop
#section('body')
#stop
This blade renders but with no master! Debugbar says that both views are rendering. Ha!
#extends('layouts.master')
#section('title')
Delete Your Pet
#stop
#section('head')
#stop
#section('intro')
<div class="output">
<h1>Delete Pet</h1>
<p>
Are you sure you want to delete <em>{{$pets->petName}}</em>?
</p>
<p>
<a href='/profile/delete/{{$pets->id}}'>Yes...</a>
</p>
</div>
#stop
#section('body')
#stop
Anyone seen this?

#stop was removed from the docs as of 5.1, so I would guess it is probably no longer supported. Use #endsection instead.
http://laravel.com/docs/5.1/blade

Related

How to change which template is extended based on user authentication

I am using Laravel 6.20.11, and I have published the Laravel blade error templates. What I need to have happen is that if the user is authenticated, the error message extends the internal-only layout, and if not, it extends the public layout like so:
#auth
#extends ('int-layouts.partials.wrapper')
#section ('error')
<div class="be-content">
<div class="main-content container-fluid">
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404 - Not Found</h1>
<p class="text-muted text-uppercase mb-4">Sorry, we couldn't find the page you were looking for.
Please contact the administrator<br/>
Or go back to the <a class="navbar-brand py-1" href="/controlpanel/">Dashboard</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#endauth
#guest
#extends ('ext-layouts.master')
#section('error')
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404</h1>
<p class="text-muted text-uppercase mb-4">Sorry,You are trying to reach the page that does not exist.<br>
Please contact the administrator <br/> Or go back to the <a class="navbar-brand py-1" href="/">Home Page</a></p>
</div>
</div>
</div>
</div>
#endsection
#endguest
The problem I am having is that when I test the 404 error using abort(404) or by trying to access a route that doesn't exist, the error message displays twice and the page inherits the int-layouts.partials.wrapper even when the user isn't authenticated.
Is this expected behavior or am I doing something wrong in my blade file?
You can try to use a conditional in one #extends directive:
#extends (auth()->check() ? 'int-layouts.partials.wrapper' : 'ext-layouts.master')
Then you can use a conditional after this inside your section.
#section('error')
#auth
#else
#endif
#endsection
The #extends directive is not actually returning output directly into the compiled result like most directives do. The compiled PHP for this is held in an array to be added later.
Everything inside the ( ) of the directive is being used as a literal to call make on the View Factory:
"<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>"
If you found the compiled view for this Blade template you would see this:
<?php echo \$__env->make(auth()->check ? 'int-layouts.partials.wrapper' : 'ext-layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
The first argument to make ends up being your view name when this compiled view is executed.
In Controller function:
$layouts = Auth::user->admin ? 'view.admin' : 'view.student'; //
view.admin or view.student is the blade file which you want to render
dynamically.
return view('welcome',compact('layouts'));
Write in Blade File:
#extends($layouts)
#section('...')
...
#endsection

Vue component does not render html under hidden dropdown-menu

<div class="dropdown notification-dropdown" data-toggle="dropdown">
<img src="{{ asset('front/img/notification-bell-ico.svg') }}" alt="">
<ul class="dropdown-menu">
<div class="card notification-card">
<div class="card-header">
<p>Notification</p>
See all
</div>
<notification :user="{{ auth()->user() }}"></notification>
</div>
</ul>
</div>
I am loading my vue component as notification as seed in above code but some how it does not render html when i click header bell icon to open it
I don't know how to resolve it
if any help will be greatly appreciated.
thanks in advance.
Your snippet looks like a blade template and notification bells are often in a site's header area. It's possible your header is not within the root element you've got Vue controlling.

Laravel replace/convert #foreach loop to vue v-for loop with database relationship

Im making a laravel SPA and I recently learned how to use vue and I know how v-for works for vue using my components. I only know how to loop only in a single table without relation thats why I'm having a difficult time changing it. I have two tables which are news and comments, and this table news hasMany comments in it.
my blade file for now.
#foreach($news->comments as $comment)
<div class="comment" style="background-color: #f6efef;" >
<div class="author-info">
<img src={{"https://www.gravatar.com/avatar/" . md5(strtolower(trim($comment->email))) . "?s=50&d=retro" }} class="author-image" id="image">
<div class="author-name">
<h4>{{$comment->name}} </h4>
<p class="author-time"> {{ date('jS F, Y - g:iA' ,strtotime($comment->created_at)) }}</p>
</div>
</div>
<div class="comment-content">
{{$comment->comment}}
</div>
</div>
#endforeach
your component goes like this in vue2.0
**block.vue**
<template>
<div class="comment" style="background-color: #f6efef;" v-for="comment in
news.comments" >
<div class="author-info">
<img :src="comment.author_image" }} class="author-image" id="image">
<div class="author-name">
<h4>{{ comment.name }} </h4>
<p class="author-time"> {{ comment.time }}</p>
</div>
</div>
<div class="comment-content">
{{ comment.comment }}
</div>
</div>
</template>
<script>
export default {
name: "block",
props: [ "news" ], //or
data() => ({ news: [] })
}
</script>

Show a collection in laravel from controller on different columns in view

got this problem:
I want to show the info from a collection where a publication has a "featured" column in true.
$pub_destacadas = Publicaciones::take(3)->where('destacado', '=', 1)->get();
The problem is that my layout has 3 elements to fill with this information that have different sizes so i wasn't able to solve this using the chunk() method in the foreach in my blade template, so I tried the following:
$individual_destacada = $pub_destacadas->take(1);
$grupo_destacada = $pub_destacadas->take(2);
and show them in the view as follows:
<div class="publicaciones-destacadas">
<div class="container">
<h2>Publicaciones Destacadas</h2>
<div class="row">
#foreach($individual_destacada as $destacada)
<div class="col-md-6">
<div class="item-destacado size-2">
<img class="img-responsive" src="{{ asset('img/publicaciones/' . $destacada->imagen ) }}">
{{ $destacada->titulo }}
{{ $destacada->descripcion }}
</div>
</div>
#endforeach
<div class="col-md-6">
#foreach($grupo_destacada as $destacada)
<div class="row doble-publicacion">
<div class="col-md-12">
<div class="item-destacado size-1">
<img class="img-responsive" src="{{ asset('img/publicaciones/' . $destacada->imagen ) }}">
{{ $destacada->titulo }}
{{ $destacada->descripcion }}
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
So... now it shows it correctly in the layout but the first item that the query gets is shown 2 times in this layout. How can I exclude this first element in the second variable where I get the featured publications?
Hope I explained the problem correctly.
Here's the layout:
You can use splice.
$individual_destacada = $pub_destacadas->splice(1);
$grupo_destacada = $pub_destacadas->splice(2);

Laravel 5.0 paginate jump to page section

I'm using Laravel 5.0 and paginate along with the render() function in my view. Rather than go back to the top of the screen after I select the next page I want it to jump to #msgs.
Here is some of my code:
<h1 class="centered" id="msgs">Announcements</h1>
#foreach($messages->getCollection()->all() as $message)
<div class="row">
<div class="row">
<div class="col-sm-9">
<h3>{{$message->title}}</h3>
</div>
<div class="col-sm-3">
<h4>From: {{$message->author_name}}</h4>
</div>
</div>
<div class="row">
<p>{{$message->text}}</p>
</div>
</div>
<hr class="featurette-divider">
#endforeach
<div class="centered">
{!! $messages->render() !!}
</div>
I'm still getting a grasp on the flow of things in laravel so I'm not really sure what to do. I tried to use append->('#msgs') but realized that its appending an array in the parameters, not appending a path to the url. I there a simple way to achieve this without overriding anything?
You might want to use fragment() method:
{!! $messages->fragment('msgs')->render() !!}
Here is the link to the documentation: Pagination - Laravel

Resources