0

I have controller in Laravel:

public function save(Request $request, ClientOrderDTO $clientOrderDTO){
        
}

Definition of above DTO looks like:

use App\DTO\ClientDTO;

class ClientOrderDTO
{
    public $id;
    public $userId;
    public ClientDTO $client;
}

And ClientDTO looks like:

class ClientDTO
{
    public $id;
}

And when I want to send post request from Angular:

save(orderDTO: OrderDTO) {
    return this.httpClient.post<RespDTO>(`${environment.apiUrl}/client-order/save`, orderDTO);
  }

I get error:

"message": "syntax error, unexpected 'ClientDTO' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)",
    "exception": "ParseError",
    "file": "C:\\xampp\\htdocs\\crm-api\\app\\DTO\\ClientOrderDTO.php",

I can't have property in class with type as another class. What is quiet popular for example in C#.

Jonson
  • 53
  • 1
  • 8
  • It seems that there is a syntax error at `public ClientDTO $client;`. This is not `typescript`. In PHP you can define variable without specifying its type. – Hamid Haghdoost May 14 '21 at 21:34
  • Yes, you're right, it works. But I saw that since PHP 7.4 it is possible declare type of property but I'm not sure – Jonson May 14 '21 at 21:53

1 Answers1

0

I have to migrate PHP from 7.3 to 7.4 version. From version 7.4 PHP allow declare types of properties

Jonson
  • 53
  • 1
  • 8