Apr 11, 2020
3
Level 33
Laravel 7 Component showing <?php echo e(session('toastr')['body']); ?>
I am following the What's New in Laravel 7: Supercharged Blade Components video, I created a Laravel 7 component using php artisan make:component Toastr and created the component (WIP). I am not sure what I am doing wrong.
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Toastr extends Component
{
public $body;
public $type;
public function __construct($type, $body)
{
$this->body = $body;
$this->type = $type;
}
public function render()
{
return view('components.toastr');
}
}
The component view looks like this
<div class="absolute right-0 mt-4 mr-4 flex justify-between items-center font-semibold p-4 text-xl text-white bg-blue-500 rounded-lg">
<span class="mr-4 text-3xl">
@svg('uam/uam-tail')
</span>
{{ $body }}
</div>
In a Laravel-Livewire component, I am calling it
public function clearCache()
{
Artisan::call('cache:clear');
Session::flash('toastr', ['body'=>'Artisan Command completed!','type'=>'info']);
} // end function
and the Laravel-Livewire component view is
{{-- @if (session()->has('toastr'))--}}
<x-toastr
type="{{session('toastr')['type']}}"
body="{{session('toastr')['body']}}"></x-toastr>
{{-- @endif--}}
Please or to participate in this conversation.