laravel 4 - Return Eloquent rows with columns based on privacy -



laravel 4 - Return Eloquent rows with columns based on privacy -

i have users table next schema:

schema::create('users', function(blueprint $table) { $table->increments('id'); $table->string('username', 50); $table->text('first_name'); $table->text('last_name'); $table->text('phone1'); $table->boolean('is_private_phone1'); $table->text('phone2'); $table->boolean('is_private_phone2'); $table->text('email'); $table->boolean('is_private_email'); $table->string('headshot', 32); $table->string('password', 64); $table->string('remember_token', 100); $table->softdeletes(); $table->timestamps(); });

i want list of users. don't want phone1, phone2, , email of have set privacy private returned (i.e. if have privacy, name , headshot returned. if don't phone , email returned).

is there way in eloquent? can think of rows, , manually loop through them , remove columns after.

alternatively, can add together scope method this:

public function scopewithprivacy($query) { if($this->isprivate('email')) { homecoming $query->select(['name', 'headshot']); } homecoming $query; }

call method like:

$user = user::withprivacy()->find(1);

so, when phone call withprivacy() method privacy check done , fields returned accordingly.

laravel-4 eloquent

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -