Skip to content

Instantly share code, notes, and snippets.

@insign
Created November 23, 2015 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insign/5ea274fa7321252b1292 to your computer and use it in GitHub Desktop.
Save insign/5ea274fa7321252b1292 to your computer and use it in GitHub Desktop.
Problemas com relacionamentos - laravel
<div class="col-md-12">
<a href="{!! action('CandidatoController@candidato', isset($pessoa->user_id) ? $pessoa->user_id : $pessoa->id) !!}">
<img src="{!! App\User::primeira_foto($pessoa->id) !!}" class="img-rounded img-responsive" alt=""/>
</a>
</div>
<div class="col-md-12">
<a href="{!! action('CandidatoController@candidato', isset($pessoa->user_id) ? $pessoa->user_id : $pessoa->id) !!}">
<img src="{!! App\User::primeira_foto($pessoa->id) !!}" class="img-rounded img-responsive" alt=""/>
</a>
</div>
<?php
// APENAS A PARTE RELEVANTE
public function fotos()
{
return $this->hasMany('\App\UserFoto');
}
?>
<?php namespace App;
use ___;
use Illuminate\Database\Eloquent\Model;
class UserFoto extends Model
{
protected $fillable = [];
protected $table = 'users_fotos';
protected $touches = ['user'];
public function user()
{
return $this->belongsTo('\App\User');
}
public function src()
{
return ___::cdn_asset("{$this->user_id}/{$this->nome}");
}
public function mini()
{
return ___::cdn_asset("{$this->user_id}/mini/{$this->nome}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment