<div >
<div >
<h4 >
{{ __('services') }}
</h4>
<i ></i>
</div>
<p >
{{ Auth::user()->services->count() }}
</p>
</div>
this is my code from the component card.blade.php
. Now the question: "Can I make a custom value that I have to specify in the tag <x-card title="" service="">
or is that not possible? I would like {{ __('services') }}
and {{ Auth::user()->services->count() }}
not to be static in the code example.
CodePudding user response:
You'd need to write a component class to handle variables in the template. That class would interpret the input and store it in variables that can be accessed in the template. This is all described in the documentation.
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Card extends Component
{
public function __construct(
public string $title,
public string $service,
)
{}
public function render()
{
return view('components.card');
}
}
Call the component like this:
<x-card title="Something" service="something else"/>
And you should then be able to use $title
and $service
in the Blade template file. Note if you want to use PHP values, you'll need to do something like this:
<x-card :title="__('something')" service="something else"/>
Note the colon preceding the attribute name.