mercredi 20 avril 2016

How to return response in laravel from trait?

I have controller:

class UserController extends Controller
{
    public function index(){
        return '1';
    }
}

now I want return code from trait like:

class UserController extends Controller
{

    use SomeTrait;
    public function index(){
        $this->traitMethod();

        return 2;
    }
}

trait SomeTrait
{
    public function traitMethod(){
        if($this->something == 1){
            return '1';
        }else{
            View::share('somethingElse', 2);
        }
    }
}

In UserController if $something = 1, trait should return 1 and rest of UserController should't be executed, how can I achieve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire