Skip to content
Snippets Groups Projects
User.php 972 B
Newer Older
Bilal Talhaoui's avatar
Bilal Talhaoui committed
<?php

Tibo's avatar
Tibo committed
namespace App;
Bilal Talhaoui's avatar
Bilal Talhaoui committed

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

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

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
btalhaoui's avatar
btalhaoui committed

    public function organizations()
    {
Tibo's avatar
Tibo committed
        return $this->belongsToMany('App\Organization');
btalhaoui's avatar
btalhaoui committed
    }
Tibo's avatar
Tibo committed

    public function ownsOrganization(Organization $organization) {
        foreach ($this->organizations as $o) {
            if ($o->id == $organization->id) {
                return true;
            }
        }

        return false;
    }

    public static function findByEmail($email) {
        return self::where("email", $email)->first();
    }