Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php loop array

/**
 * Get the author of the post.
 */
public function user()
{
    return $this->belongsTo(User::class)->withDefault([
        'name' => 'Guest Author',
    ]);
}

/**
 * Get the author of the post.
 */
public function user()
{
    return $this->belongsTo(User::class)->withDefault(function ($user, $post) {
        $user->name = 'Guest Author';
    });
}
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #php #loop #array
ADD COMMENT
Topic
Name
8+7 =