dimanche 1 novembre 2015

Secure and clean code in laravel 5.1

In fact i have a question about the clean of code
i try to get some value in blade file , I Am confused between two approaches i think both are right but i need to know who's clean and secure more with the reason

First approach in my blade directly using Eloquent

@foreach (Auth::user()->company->country->cities as $city) {{$city->name}} @endforeach

Second approach using Injecting Services by create this method in my model and use it in my blade using laravel 5.1 Injecting Services

 public function getCity()
{
    foreach(Auth::user()->company->country->cities as $city) {
        return $city->name ;
      // OR 
        return $city ;  
          //  i think this is one of benefits to use this approach   
          //  because in my view i can  use getCity()->id or getCity()->name
    }
}

Thanks For Your Time .



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1k1v7tG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire