Tema: Friendly api
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 31/03/2016, 08:17
Avatar de Dundee
Dundee
 
Fecha de Ingreso: junio-2002
Ubicación: El Médano
Mensajes: 1.310
Antigüedad: 21 años, 10 meses
Puntos: 8
Respuesta: Friendly api

Solucionado (pero no entiendo del todo porque no puedo hacerlo todo desde el controlador).

En mi controlador tengo ahora esto:
Código:
    public function ask_friend($requesterId, $receivingId) {
        
        // Requester user.
       $userRequester = User::where('id', $requesterId)->first();  
        
        // Receiving user.
       $userReceiving = User::where('id', $receivingId)->first();
       
       return $userRequester->request_friend_ship ($userRequester, $userReceiving);        
      
    }
Y en el modelo user:
Código:
<?php

namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword, \GridPrinciples\Friendly\Traits\Friendly;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['email', 'password'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];
    
    public function profile()
    {
        return $this->hasOne(Profile::class); // links this->id to events.course_id
    }
    
    public function request_friend_ship ($userRequester, $userReceiving) {

        
        // may include "pivot" data.
        $query_friend = $userRequester->befriend($userReceiving, [
            'name'       => $userReceiving->email,
            'other_name' => $userRequester->email,
            'start'      => date('Y-m-d') ,
        ]);
        
        return $query_friend;
    
    }
    
  
}
__________________
Videotutoriales de Drupal