Laravel changing function/text of a button depending on value -


i'm using laravel 5 , have button "enable" once pressed sets flag in db 1. works fine code below:

blade view

{!! form::open(['url' => '/cms/user/' . $user->id . '/flag', 'method' => 'put']) !!}                                 {!! form::hidden('flagged', !$user->flagged) !!}                                 {!! form::submit('flag', ['class' => 'btn btn-success'])!!}                                 {!! form::close() !!} 

controller

/**  * update specified resource in storage.  *  * @middleware({"auth"})  *  * @param  int $id  * @put ("cms/user/{user}/flag",as="cms.users.update.flag")  * @return response  */     public function updateflag($id)         {             $user = user::find($id);             //dd(input::get('flagged'));             $user->flagged = input::get('flagged');              $user->save();              session::flash('message', 'successfully flagged idea!');             return redirect()->route('cms.users.index');         } 

now i'm trying work out changing button once user flags it. i.e.: first time button should "enable" (db value 0). press button , updates flag in db 1 (which works fine).

but now, after button pressed, how change button text "disable" can disable user on pressing button. kind of on/off switch can enable/disable user updating button text , function based on flagged value in db.

pass boolean variable view (apparently have variable contains information):

return redirect()->route('cms.users.index')->with(['flag' => $flag]); 

then in view make if/else:

@if($flag)     {!! form::submit('enable', ['class' => 'btn btn-success', 'disabled' => 'disabled']) !!} @else     {!! form::submit('enable', ['class' => 'btn btn-success']) !!} @endif 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -