Hi guys,
I use PHPStorm with Laravel IDE and Alpine.js plugin.
I have simple usecase sometimes, for example :
@php
if(!isset($parameters['servers'])) {
// get all allowed ftp servers for actual user with all available options
$ftpServers=\App\Models\Ftpserver::where('ftpdispo', 1)->allowed();
$exportFtpService=new \App\Services\ExportFtpService();
$servers=$exportFtpService->getServersWithAllOptions($ftpServers);
}
else { // use already known servers (previous movement)
$servers=$parameters['servers'];
}
@endphp
<div
x-data="{
parameters: @entangle('parameters'),
servers: {{ json_encode($servers) }},
init(){
// skip this step
{{ $skipThisStep === true ? '$wire.'.$processMove.'();' : '' }}
$nextTick(() => {
this.isLoading = false;
this.isValid = false;
// parameters.servers already defined (e.g. previous)
if(this.parameters.servers){
// check if there's at least one selected server
this.isValid = this.parameters.servers.some(subItem => subItem.selected === true);
}
$focus.first();
});
},
}"
class="..."
>
<h4>{{ __('step-processes.export_process_step4_headline') }}</h4>
<form
id="stepForm{{$currentStepId}}"
@submit.prevent="submit()"
>
<x-sandbox.server-choices :servers="$servers"/>
</form>
</div>
The problem is that all the JS is not understood (green color for all the x-data's init).
If I change the alpine declaration like so :
servers: '{{ json_encode($servers) }}',
By adding quotes, it understands the rest of the JS but the array is not well processed anymore.
I don't know how to fix all of this.
If you have an idea, I am very interested.