setPasswordAttribute in Laravel
eloquent, laravel-4, php
Solution
They are called Accessors and Mutators.
See Laravel documentation for more information.
They allow you to define behaviour when you set (mutator) or get (accessor) variables from your Eloquent models.
Another example would be
public function setUsernameAttribute($value){
$this->attributes['username'] = strtolower($value);
}
Problem
I was trying to seed DB in Laravel with the given data, and i saw a snippet about HASH::make, mentioning it in The Model not in Seeder file.. TaskerTableSeeder.php ``` class TaskerTableSeeder extends Seeder{ public function run(){ Tasker::truncate(); Tasker::create([ 'username'=>'junni', 'email'=> 'junni@gmail.com', 'password'=> 'Junaid' ]); Tasker::create([ 'username'=>'test', 'email'=> 'test@gmail.com', 'password'=> 'Test' ]); Tasker::create([ 'username'=>'poni', 'email'=>'poni@loni.com', 'password'=>'Poni' ]); } } ``` and I Put that Code in my Tasker Model for Hash::make ``` class Tasker extends Eloquent{ public function setPasswordAttribute($value){ $this->attributes['password'] = Hash::make($value); } } ``` it is the way to make your password HASH encrypted, but i didn't find any information about setPasswordAttribute Function in Laravel Documentation.. and how many other attributes are there for which we can use such type of Functions.