Created
November 23, 2015 16:34
-
-
Save insign/69d43df32a03b4233c8b to your computer and use it in GitHub Desktop.
Problemas com relacionamentos - laravel (Error: Call to undefined method Illuminate\Database\Query\Builder::mini())
This file contains 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 | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
class CreateUsersFotosTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('users_fotos', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->integer('user_id')->unsigned(); | |
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | |
$table->string('nome'); | |
$table->boolean('principal')->nullable(); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('users_fotos'); | |
} | |
} |
This file contains 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
<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> |
This file contains 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
<div class="col-md-12"> | |
<a href="{!! action('CandidatoController@candidato', isset($pessoa->user_id) ? $pessoa->user_id : $pessoa->id) !!}"> | |
<img src="{!! $pessoa->fotos()->mini() !!}" class="img-rounded img-responsive" alt=""/> | |
</a> | |
</div> |
This file contains 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 | |
// APENAS A PARTE RELEVANTE | |
public function fotos() | |
{ | |
return $this->hasMany('\App\UserFoto'); | |
} | |
?> |
This file contains 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; | |
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