Undefined Slot variable in Laravel - laravel

I am getting an error which is "Undefined variable: nav"
In my home.blade.php,I have this code
#extends('master')
#section('content')
{!! $nav !!}
#endsection
And in my header component(header.blade.php)
#component('component.header')
#slot('nav')
new html
#endslot
#endcomponent
Can you help?
FYI my component is in a component directory in views and home is in views directory

Related

Passing variables to email footer in Laravel

I would like to show a disclaimer in the footer saying
This email was sent to {recipients email address}.
but i can't figure out how i can get the email address into the standard footer blade.
Here is what I have:
In my notification component I make the following call with $rcp_email having the email address of the recipient:
return (new MailMessage)
->subject('Contact Form Submitted')
->markdown('emails.generic.contactform', [
'first_name' => $this->first_name,
'message' => $this->message,
'rcp_email' => $this->rcp_email,
'url_security_issue' => $url_security_issue,
]);
The emails.generic.contactform looks like this
#extends('emails.main')
#section('content')
(body of email)
#endsection
emails.main looks like this
#component('mail::message')
#yield('content')
#if (isset($unsubscribe_url))
(html code for unsubscribe)
#endif
#endcomponent
the standard vendor\mail\html\message blade looks like this:
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.front_end_url'), 'logo' => asset('logo-image-white-circular-background.png')])
{{ config('app.name') }}
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. #lang('All rights reserved.')
#endcomponent
#endslot
#endcomponent
I traced each level of blade and $rcp_email is first of all not availble in the message blade. I tried to pass it on by changing the first line of emails.main to
#component('mail::message', ['rcp_email' => $rcp_email])
but in either case when i try to use the variable in the message blade, i get the error Undefined variable: rcp_email
In an ideal case, I would want to add the html code and make use of the variable in the actual footer blade, but I don't know if that's possible.
I would much appreciate if there is any hints/any docus or articles you can share that describes in depth how this works?
Thanks,
Goppi
hopefully this helps for others with issue
From what I did, when you use #component('mail::message', ['rcp_email' => $rcp_email]) it will pass the variable $rcp_email to the message blade.
Here change your message blade #component('mail::footer') to #component('mail::footer', ['rcp_email' => $rcp_email]) to pass it again to your footer blade.
In footer blade access the variable like {{$rcp_email}}
so example would be <p>sent to {{$rcp_email}}</p>
Also as a note, when passing the variable like ['name' => $variable] it uses the name as the variable in the next blade. so here you would access it like $name
Thanks #Jack C - your solution didn't work for me back then as you can see from my original post. I tried to pass rcp_email on to the message blade using
#component('mail::message', ['rcp_email' => $rcp_email])
and when I tested $rcp_email within the message blade, it came back with undefined variable. That said, I didn't figure out why it wasn't working, but I used #component with variables for other blades without issues. Perhaps it didn't work due to caching issue.
The solution that I came up with back then opened itself up once I decided not to use the standard email template, but design my own.
The emails.generic.contactform changed as follows:
#extends('emails.layout.layout')
#section('content')
{{-- body of email --}}
#endsection
The emails.layout.layout blade looks like this:
#component('mail::layout')
{{-- Content --}}
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
{{ $recipient ?? '' }}
#endcomponent
#endslot
to summarize, my understanding on how to pass variables between blades is as follows:
extend - extends allows the layout blade to use all variables with the same names as the extended blade.
#extends('layout')
components have no access to the variables of the parent blade. Instead they need to be passed on. There are two ways to pass them on: as one or more variables or as a slot. In the example below $name is available within the component footer.
#component('footer', ['name' => $rcp_email])
#endcomponent
component - the second way is as a slot. In the example below the variable $slot would contain the email address.
#component('footer')
{{ $rcp_email }}
#endcomponent

[Vue warn]: Property or method "permissionsSelected" is not defined on the instance but referenced during render

I'm trying to auto check active permissions, but vue does not work. Can someone explain what's the problem ? because im not wery experienced with this stuff.
Console Output:
[Vue warn]: Property or method "permissionsSelected" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
#extends('template.default')
#section('content')
<form action="{{ route('roles.update', $role->id) }}" method="POST">
{{ csrf_field() }}
{{ method_field('PUT') }}
<input type="hidden" :value="permissionsSelected" name="permissions">
<h5>Permissions:</h5>
#foreach ($permissions as $r)
<el-checkbox v-model="permissionsSelected" :native-value="{{$r->id}}"> {{$r->display_name}} <em>({{$r->description}})</em></el-checkbox>
#endforeach
</form>
#endsection
#section('scripts')
<script>
var app = new Vue({
el: '#app',
data: {
permissionsSelected: {!! $role->permissions->pluck('id') !!}
}
});
</script>
#endsection
if you have a vue instance in app.js or in any shared js file, delete it #Leonardo H
It seems like you are initializing the Vue on #app but there is no element with that id.
Try adding an id to form:
<form id="app" action="{{ route('roles.update', $role->id) }}" method="POST">
EDIT: if you want to extend an already initialized Vue instance, use Vue.extend
EDIT2: when using laravel and blade templating, to avoid these kind of issues, I would instead use a .vue file with a prop to get data inside the component and do what ever with that data inside it. In this way it is avoided multiple instantiations of Vue and the code is more granular and better structured.

CKEditor issue with Laravel 5

I have a problem with CKEditor, it return me this result : <p style="text-align:center"><span style="font-family:Lucida Sans Unicode,Lucida Grande,sans-serif"><span style="font-size:14px">News content blah blah blah</p> instead of the text itself. I did successfully loaded the editor to form. Here is the form code :
{!! Form::textarea('abstrak', null, ['class' => 'form-control ckeditor']) !!}
the view that supposed to show the result :
<h5>{{ $jurnal->abstrak }}</h5>
and I load the js file from master template :
<script src="{{ asset('ckeditor/ckeditor.js') }}"></script>
is there something I missed here ? thankyou
Instruct Laravel Blade to not escape HTML characters by replacing your code with
<h5>{!! $jurnal->abstrak !!}</h5>

Method render does not exist

I am trying to render my view but i got error
its says Method render does not exist . (View:
my view is
#foreach($forumindex->forumindex()->paginate(2) as $comment)
<p><div class="well">{{ $comment->comment }}</div></p>
#endforeach
{!! $forumindex->forumindex->render() !!}
when i remove {!! $forumindex->forumindex->render() !!} its working fine and i see only 2 post
help me i don't know what code is right
The render() method to build the paginator view has been renamed to links() on Laravel 5.2.
Source: https://laravel.com/docs/5.2/pagination

Laravel white page loading route

I had a login.blade.php with some code, and I decided to replace with a new one.
I renamed it to old_login.blade.php and create a new file, in the same path, with the name login.blade.php.
After a while, I decided to rollback to my old login page.
I delete login.blade.php, and renamed the old_login.blad.php with the original name to return back.
No code was edited, only views.
The problem is that the page returned a blanck white page with many comments (the comment's tag is not closed).
I try to make a copy of the view, called test.blade.php, and change the route to that view. It diplay them correctly. But If I change another time route to myapp.login to display login.blade.php view, it won't work.
I try anything but nothing is changed. I'm using laravel 5.1.
The code insiede my routes.php is
Route::get('/', function () {
return view('myapp.login');
});
the code inside the login.blade.php (same ad test.blade.php) is:
#extends("app")
#section("content")
{!! Form::open(["url" => "home"]) !!}
<div class="form-group">
{!!Form::label("username", "Username:") !!}
{!!Form::text("usr_username", "Luca", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::label("password", "Password:") !!}
{!!Form::input("password", "usr_password", "mypass", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::submit("Login", ["class" => "btn-primary form-control"]) !!}
</div>
{!! Form::close() !!}
#include("errors.list")
#stop
So a nonsense answer to resolve my problem: I cutted the code inside login.blade.php, save file, pasted it, and saved another time. Now it display correctly.

Resources