Mynde Mindaugelis
Mynde Mindaugelis

Reputation: 105

Laravel if option value ==

I need any suggestion how can i do that. Example what i trying todo:

I have option value called "Ban reason":

If i choose "Cheating" i put reason "Chating" into mysql. That's ok with my code:

 DB::table('server_bans')->insert(['reason' => Input::get('player_reason')

My view:

<select id="player_reason" name="player_reason"><option value="" selected="selected">-</option>
<option value="Cheating">Cheating</option>
<option value="No reason">No reason</option>
</select>

But i need to add into sql "Ban time" by reason using minutes. Example:

If i choose "Cheating" from option value, it goes reason and banlength for 360days by using minutes timer (518400 minutes)

Any suggestion how can i do that? Thanks for helping me!

Upvotes: 2

Views: 77

Answers (1)

Brian Lee
Brian Lee

Reputation: 18197

You just need to switch on the reason and set a variable in your controller method when saving the ban reason.

public function banUser (Request $request) {
    $reason = $request->get('player_reason');

    switch ($reason) {
        case 'Cheating':
            $banlength = 518400;
            break;
        case 'No Reason':
            $banlength = 1;
            break;
        default: 
            $banlength = 0;
            break;
    }

    DB::table('server_bans')->insert(compact('reason', 'banlength'));

    return back();
}

Upvotes: 5

Related Questions