Last active
March 10, 2017 20:15
-
-
Save tiagoandrepro/99862928376ea69251c0897636aa9d3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use Illuminate\Database\Eloquent\Model; | |
use App\Models\Nature; | |
class Establishment extends Model | |
{ | |
// | |
public $table = "estabelecimento"; | |
protected $fillable = ['nmFantasia']; | |
public function specialty () { | |
return $this->belongsToMany(Specialty::class, 'estabelecimento', 'idUnidade'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Web; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use App\Models\Establishment; | |
use App\Models\Nature; | |
use App\Models\Specialty; | |
class SearchController extends Controller { | |
public function search (Establishment $establishment) { | |
$search = \Request::get('result'); | |
if ($search) { | |
//$establishmens = $establishment->all(); | |
$establishmens = $establishment::where('nmFantasia', 'like', '%'.$search.'%')->paginate(25); | |
return view('web.search', compact ('establishmens') ); | |
} else { | |
return 'Nenhum termo digitado'; | |
} | |
} | |
public function teste () { | |
$nature = Specialty::where('nmEspecialidade', 'like', '%ATENCAO%')->get()->first(); | |
echo $nature->nmEspecialidade; | |
$unidades = $nature->establishments; | |
foreach($unidades as $unidade) { | |
echo $unidade->idUnidade; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use Illuminate\Database\Eloquent\Model; | |
class Specialty extends Model | |
{ | |
// | |
public $table = "especialidade"; | |
protected $fillable = ['nmEspecialidade']; | |
public function establishments () { | |
return $this->belongsToMany('App\Models\Establishment', 'especialidade_estabelecimento', 'especialidade_idEspecialidade', 'estabelecimento_idUnidade'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment