Helper function – array_add() (laravel 5.2): link

The method appends the key/value pair  to the existing array.  This can be useful when adding additional fields when creating new record with request all() method. If the form and database field names are same than just pass the request->all() method. If you still see that the input is not creating new record than you must define all your fillable fields under the model.

For example:

$new_department = Department::create(array_add($request->all(),'company_id',Auth::user()->company->first()->id));


$data = $request->all();
$data['company_id'] = Auth::user()->company->first()->id;

Use pluck vs list (laravel 5.2) : link 

The pluck method returns an array. Both method to do the same thing.

For example:

 $this->departments->whereCompanyId(Auth::user()->company->first()->id)->pluck('name', 'id')

Leave a Reply

Your email address will not be published. Required fields are marked *