hello,
reviewing the documentation, it seemed that, to pass variable from partial to composer, was enough to
@include('partial.file', ['data1' => 'value', 'data2' => 'value2'])
and in
File.php
public function with()
{
return [
'myVar' => $this->my_function($data),
];
}
public function my_function($data) {
//access to $data
//$data['data1']
//$data['data2']
//etc
}
BUT
this seems not to work anymore, as it generates an error
Declaration should be compatible with Composer->with()
so… what now?
how can I access those values?
ty
I think you have two things going on here.
One is that with()
is protected
, not public
, hence the complaint about “Declaration should be compatible”.
The second is that to access the current data, you need to use $this->data
. If your with()
example you’re pulling the $data
variable out of thin air. It would need to be something more like:
public function myFunction() {
return $this->data['data1'];
}
ok, it’s not working 
real case scenario:
Pinned.php
public function with()
{
return [
'pinnedPosts' => $this->getPinnedPosts(),
'id' => $this->getID(),
];
}
public function getID()
{
return $this->data['pageID'];
}
homepage.php
@include('partials.pinned', $data = ['pageID'=> get_the_ID()])
pinned.blade.php
ID: {!! $id !!}
but the result is…
ID:
ty
What debugging steps have you already tried? Have you checked the value of the data property in the composer?
sorry, you are right.
...
return $this->data;
....
returns this:
Illuminate\Support\Fluent Object ( [attributes:protected] => Array ( ) ) 1