Larry Mckuydee
Larry Mckuydee

Reputation: 503

Laravel 5 Function name must be a string bug

I get fatal error:

Function name must be a string

When try to return $redirect()->to(blah blah blah...

    if($act=="ban"){
        $ban_until = $request->input('ban_until');
        if(Ragnarok::temporarilyBan($account_id,$banned_by,$ban_until,$ban_reason)){
            return $redirect()->to('banlist');
        }else{
            return $redirect()->to('banlist')->withErrors('Failed to ban, database error');
        }
    }else if($act=="unban"){
        if(Ragnarok::unBan($account_id,$banned_by,$ban_reason)){
            return $redirect()->to('banlist');
        }else{
            return $redirect()->to('banlist')->withErrors('Failed to unban, database error');
        }
    }

Anybody face this bug?

Upvotes: 4

Views: 27759

Answers (2)

haakym
haakym

Reputation: 12358

Try removing the $ from the function as so:

redirect()->to('banlist');

PHP functions must begin with a letter or underscore, you have mistakenly added a $ to the function.

From the PHP Docs:

Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

http://php.net/manual/en/functions.user-defined.php

Upvotes: 5

Jamesking56
Jamesking56

Reputation: 3901

redirect() is a function in Laravel not a variable so does not require the $ sign.

Upvotes: 4

Related Questions