Check if call is method chaining PHP

php method-chaining

87 просмотра

1 ответ

I want to know about method chaining. Recently I have used method chaining in Laravel, it's working fine.

My Model name was Posts so when I want to select all names from posts it returns all names.


And when I call below function to get one records it gives only one record.


I want to implement same scenario in my own class. I have a class of image uploading.

If I will upload only a file, it will be


But If I upload image with resize and watermark.

Image::upload('pic')->resize(200, 300)->addwatermark('image/logo.png');

Автор: Zartash Zulfiqar Источник Размещён: 08.11.2019 10:58

Ответы (1)

0 плюса


Basically your methods must do : "return $this;" once treatment is done :

public function upload(){
    //do something

    return $this;

public function resize(){
    //do something

    return $this;

public function watermark(){
    //do something

    return $this;
Автор: vincenth Размещён: 20.08.2016 08:44
Вопросы из категории :