dimanche 1 mai 2016

Updating data from controller to database in laravel

I want to update data from laravel controller to database, I am able tto update data in model but I am not able to update data into database

here is my View or HTML coding

function editdata(data)
{
    //alert(data);
    $(function(){
      $.ajax({
        method : "GET",
        url: "welcome",        
        data: {id: data},        
        success : function(response)
        {
          //debugger;
          /*if(response==true)
            alert("success");
          else
            alert("Failure");*/
          var a=response;
          //$('#fname').value(a.fname);
          $('#firstName').val(a.fname);
          $('#lastName').val(a.lname);
          $('#qualification').val(a.qualification);
          $('#emailAddress').val(a.email);
          $('#contactmessage').val(a.desc);
          var elem = document.getElementById("add");
          elem.value="Update";

        }

      });


    });
}
function disableData(data)
{
    //alert(data);
    //if (confirm('Are You Sure You Want To Delete Data ?')) {


    $(function(){
      $.ajax({
        method : "GET",
        url: "welcome/disable",        
        data: {id: data},        
        success : function(response)
        {

          //alert(response);
          window.location.reload();
          //debugger;
          /*if(response==true)
            alert("success");
          else
            alert("Failure");*/
          //alert('Data is deleted Successfully!!!');

        }

      });


    });

    //} else {
    //alert('Data is not deleted');
    //}
}
function addUpdateData(data)
{
   var btnvalue = document.getElementById("add").value;
   //alert($('#firstName').val)
      //alert(btnvalue);
   if(btnvalue=="Add")
   {
      $(function(){
          $.ajax({
            method : "GET",
            url: "welcome",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: dataToSend,

            success : function(response)
            {
              alert("data sent successfully");
          //debugger;
          /*if(response==true)
            alert("success");
          else
            alert("Failure");*/

           }

          });
      });
   }
   else
   {
      $(function(){
          $.ajax({
            method : "GET",
            url: "welcome",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: dataToSend ,

            success : function(response)
            {
              alert("data sent successfully");
          //debugger;
          /*if(response==true)
            alert("success");
          else
            alert("Failure");*/

           }

          });
      });
   }
}

/*function addData(data)
{
    $function(){

      $.ajax({

        method : "post",
        url: "welcome",
        data: {id: data,}
      })
    }
}*/

</script>

</head>


<body>

<div class="container-fluid" style="background-color: #CCCCCC">

  <h1>Temp Form</h1>
            <form method="post" action="" role="form">


           <input type="hidden" name="_token" value="">

          <div class="panel panel-default ">

            <div class="container">

            <div class="panel-body">
              <div class="form-group">
                <label for="firstName">First Name *</label>
                <input name="fname" type="text" class="form-control" id="firstName" placeholder="Enter First Name" required>
              </div>

              <div class="form-group">
                <label for="lastName">Last Name *</label>
                <input name="lname" type="text" class="form-control" id="lastName" placeholder="Enter Last Name" required>
              </div>

              <div class="form-group">
                <label for="qualification">Qualification *</label>
                <input name="qualification" type="text" class="form-control" id="qualification" placeholder="BE, MCA, MBA Etc." required>
              </div>

              <div class="form-group">
                <label for="emailAddress">Email address *</label>
                <input name="email" type="email" class="form-control" id="emailAddress" placeholder="Enter Email" required>
              </div>

              <div class="form-group">
                <label for="contactmessage">Message</label>            
                <textarea name="desc" type="text" class="form-control" id="contactmessage" placeholder="Message" rows="2"></textarea>
              </div>              





                <input type="submit" id="add" class="btn btn-primary" onClick="addUpdateData(id)" value="Add"></button>
              </div>
          </div>
        </div></form>


        </div>
        <div class="container">
        <div class="container-fluid">
           <h1>All Data</h1>

           <div class="row">
            <table class="table table-hover">
              <thead>
                <tr>
                 <th> First Name </th> <th> Last Name </th>
                  <th> Qualification </th> <th> E-mail </th> <th> Description </th>
                </tr>
              </thead>
              <tbody>
                @foreach ($forms as $form)
                  <tr>

                    <td>  </td>
                    <td>  </td>
                    <td>  </td>
                    <td>  </td>
                    <td>  </td><br>
                    <td> <a id="" onClick="editdata(id)" class="btn btn-info">
                         <span class="glyphicon glyphicon-edit"></span></a></td>
                    <td><a id="" onClick="disableData(id)" class="btn btn-danger">
                          <span class="glyphicon glyphicon-trash"></span>
                         </a></td>
                    </td>
                  </tr>
                @endforeach
             </tbody>
           </div>
        </div>

        </table>
          </body>


  </html>

Here is code for controller

<?php

namespace App\Http\Controllers;

use DB;

use App\Basicusers;
use Request;

use App\Http\Requests;

class FormController extends Controller
{
    //$flag = "Add";
    public function show()
    {
        //return 'FormController';
        $forms = Basicusers::all()->where('flag',1);
        //$name = ['Nix','Shiv'];
        //return view('welcome',compact('name'));
        return view('welcome',compact('forms'));
    }
    /*public function addNew(Request $req)
    {
        $bs = new Basicusers;


        $bs->fname = $req->fname;
        $bs->lname = $req->lname;
        $bs->qualification = $req->qualification;
        $bs->email = $req->email;
        $bs->desc = $req->desc;

        $bs->save();

        return back();
        //return "Success";
    }*/
    public function editdata()
    {

        //return "Editdata called";
        //$data = Basicusers::find($id);
        //$flag = "Update";
        //return view('edit',compact('data')));
        $id = $_GET['id'];
        //$id = Request::get();
        $data = Basicusers::find($id);
        //return view('welcome',compact('id'));

        return $data;

        //return $id;
       // $category = Input::get('productCategory');
        //$id = Request::get('id');
        //$data = Basicusers::find($id);
        //return $data;
        // 1exit;
        //return $data;
        /*htmlForm::open();
        Form::textarea('fname','Nirav');
        Form::close();
        return back()*/;
        //$form = Basicusers::find($id);
        //return view('welcome',compact('form'));
    }
    public function disableData()
    {

        $id = $_GET['id'];

        //$update = DB::table('basicusers')->where('id',$id)->update('flag','0' );
        $alldata = Basicusers::find($id);

        //$original = $alldata->flag;

        $alldata->flag = 0;

        $alldata->save();
        //$alldata.update('flag',0);
        //$alldata.save();
        //$update->save();
        return $alldata->flag;
        //Basicusers::find($id)->delete();

        //Basicusers::where('id',$id)->update('flag',0);

        //return "success";

    }
    /*public function addUpdateData(Request $request)
    {
        /*$formupdate = Request::all();
        $form = Basicusers::find($id);
        $form->update($formupdate);

        return redirect('/');*/
        //if($flag=="Add")
            //print_r("Data Will be Added");
       // if($flag=="Update")
           // print_r("Data Will be Updated");
        //else
            //print_r("Error");
        //print_r($formupdate);
        //$input = Input::all();
        //return response()->json($input); //- See more at: http://ift.tt/1rbHuGH
    }*/
}

I am able to get data using following commands

    $id = $_GET['id'];//id of data to be disabled
    $alldata = Basicusers::find($id);//row for which data will be disabled
    $alldata->flag = 0;//setting values
    $alldata->save();//saving data
    return $alldata->flag;//returning new value

However from the above code Data is not updated in database How to update data in database please guide

after clicking on delete button, I just want to disable data(don't want to fetch that row) I have column called flag where binary values 0 or 1 stored.

I am fetching only those records where the value of flag is 1

so on delete I want to make flag value for that record to 0



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1W2trRe
via IFTTT

Laravel 5.2 + Modify default login Behavior + Throllting stopped working

I have created new project in Laravel 5.2 and tried to modify default behavior of Auth-Login.

Created new method called postLogin which is being called when login form is submitted.

Below is the code I have written to achieve login throttling in postRegister Method.

protected function postLogin(AuthLoginRequest $request){

    $credentials = $this->getCredentials($request);
    $credentials['is_activated'] = "Yes";

    $remember = $request->has('remember');

    $throttles = $this->isUsingThrottlesLoginsTrait();


    if ($throttles && $this->hasTooManyLoginAttempts($request)) {
        return $this->sendLockoutResponse($request);
    }

    if (Auth::guard($this->getGuard())->attempt($credentials, $remember)) {
        // add login in case of success
        return $this->handleUserWasAuthenticated($request, $throttles);
    } else {
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }

        return redirect("/login")
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }
}

While debugging, I found that $this->hasTooManyLoginAttempts($request) method never returns true.

Can someone please notify me what I am lacking in order to make this work?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1W2s6tx
via IFTTT

Convert array to Request object in laravel 5

I have store method in user controller like this

public function store(Request $request)
{
    User::create($request->all()); 

}

and in another controller I want use this method

 public function test(Request $request)
{
  .....
   app('\App\Http\Controllers\UserController')->store($request);
  ...
}

and $request is:

{"name":"test","email":"test@gmail.com"}

and finally show me error this

Argument 1 passed to App\Http\Controllers\UserController::store() must be an instance of Illuminate\Http\Request,

How can I convert array to Request object?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1rbBduk
via IFTTT

sphinxsearch Laravel 5.2 "Nothing to publish for tag []."

I have install sphinxsearch on my system and working fine for core php. Now i want to use it for laravel 5.2 . I have followed these step

1) install composer
2) 'providers' => array(
        'Scalia\SphinxSearch\SphinxSearchServiceProvider',
    )
3) 'aliases' => array(
      'SphinxSearch' => 'Scalia\SphinxSearch\SphinxSearchFacade',
    )
4)  php artisan config:clear

5)  php artisan config:publish scalia/sphinxsearch
    error [InvalidArgumentException]                
       Command "config:publish" is not defined.  
       Did you mean one of these?                
         vendor:publish                        
         config:clear                          
         config:cache 

 6) php artisan vendor:publish --provider=sngrl\SphinxSearch\SphinxSearchServiceProvider --force
    Nothing to publish for tag [].

How can i configure sphinxsearch in laravel



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WBE2ks
via IFTTT

radio button onchange load controller Laravel 5

On my website I want to have the functionality where a person has two ways of signing in .

  • Using a specific number
  • His or hers firstname and surname

To achieve this i'm using a two radio buttons. one for each of the two I mentioned above.

The thing i'm trying to achieve is: When the state of a button changes then a controller needs to load and the registration form has to be updated accordingly.

The code i'm using:


<div class="row">
    <div class="form-group">
        <label class="col-xs-6 col-sm-4 col-sm-offset-1">Do yo have your number at hand?</label>
        <div class="col-xs-2">
             Yes
        </div>
        <div class="col-xs-2">
             No
        </div>
    </div>
</div>




from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1O85AHu
via IFTTT

Trying to get property of non-object in Laravel unserializing array from database

I have the following class in my code.

class ReportField extends Model
{
    //
    public $name;
    public $quantity;
    public $unitCost;
    public $totalCost;
    public $estimation;
}

I write an array of these objects to a database using serialization.

$fieldsList=array();
foreach($items as $item){
        if($item->sale_type == 1){

                $reportField=new ReportField();
                $reportField->name=$item->item_name;
                $reportField->unitCost=$item->unit_cost;
                array_push($fieldsList,serialize($reportField));
         }
}

$gpForecast=new GPForecast();
$gpForecast->project_id=$project_id;
$gpForecast->fieldList=(serialize($fieldsList));
$gpForecast->save();

After unserialization now i want to convert those objects in array to RecordField objects.

$gpForecast=GPForecast::all()->first(); //here i read one of array i write to database
$fieldList=unserialize($gpForecast->fieldList );
foreach($fieldList as $field){
       echo $field->name;
}

But then I get the error Trying to get property of non-object So how can I correct this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TnMPl4
via IFTTT

Moved a Laravel project from one computer to another and getting a route error

I moved a laravel project from one computer to another and i'm getting rout error's. One thing that's strange is the url's on the previous computer had http://localhost:8000/public/order/create but on the new computer its http://localhost:8000/order/create

If i add the public manually it still doesnt work. Any ideas?

Error:

NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 823
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in     CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
at require_once('/Users/mccray/Desktop/owe/public/index.php') in server.php line 21

Route File:

 Route::group(['middleware' =>[ 'web']], function () {
  Route::any('user/login', ['as' => 'user.login', 'uses' => 'UserController@login']);
Route::any('user/dologin', ['as' => 'user.dologin', 'uses' => 'UserController@dologin']);});

Route::group(['middleware' =>[ 'web','auth']], function () {
Route::any('/', function () { return view('user.dashboard'); });
Route::any('user/dashboard', ['as' => 'user.dashboard', 'uses' => 'UserController@dashboard']);
Route::any('user/logout', ['as' => 'user.logout' , 'uses' => 'UserController@logout']);

Route::any('sos/create', ['as' => 'sos.create', 'uses' => 'SosController@create']);
Route::any('sos/index', ['as' => 'sos.index' , 'uses' => 'SosController@index']);
Route::any('sos/store', ['as' => 'sos.store' , 'uses' => 'SosController@store']);
Route::any('sos/show/{id}', ['as' => 'sos.show' , 'uses' => 'SosController@show']);
Route::any('sos/edit/{id}', ['as' => 'sos.edit' , 'uses' => 'SosController@edit']);
Route::any('sos/update/{id}', ['as' => 'sos.update' , 'uses' => 'SosController@update']);
Route::any('sos/destroy/{id}', ['as' => 'sos.destroy' , 'uses' => 'SosController@destroy']);
Route::any('sos/submit/{id}', ['as' => 'sos.submit' , 'uses' => 'SosController@submit']);
Route::any('sos/approve/{id}', ['as' => 'sos.approve' , 'uses' => 'SosController@approve']);
Route::any('sos/reject/{id}', ['as' => 'sos.reject' , 'uses' => 'SosController@reject']);
Route::any('sos/customer-search', ['as'=>'sos.customer-search','uses'=>'SosController@search']);
Route::any('sos/customer-selected', ['as'=>'sos.customer-selected','uses'=>'SosController@customerSelected']);

Route::any('order/create', ['as' => 'order.create', 'uses' => 'OrderController@create']);
Route::any('order/index', ['as' => 'order.index' , 'uses' => 'OrderController@index']);
Route::any('order/store', ['as' => 'order.store' , 'uses' => 'OrderController@store']);
Route::any('order/show/{id}', ['as' => 'order.show' , 'uses' => 'OrderController@show']);
Route::any('order/edit/{id}', ['as' => 'order.edit' , 'uses' => 'OrderController@edit']);
Route::any('order/update/{id}', ['as' => 'order.update' , 'uses' => 'OrderController@update']);
Route::any('order/destroy/{id}', ['as' => 'order.destroy' , 'uses' => 'OrderController@destroy']);
Route::any('order/submit/{id}', ['as' => 'order.submit' , 'uses' => 'OrderController@submit']);
Route::any('order/approve/{id}', ['as' => 'order.approve' , 'uses' => 'OrderController@approve']);
Route::any('order/reject/{id}', ['as' => 'order.reject' , 'uses' => 'OrderController@reject']);
Route::any('order/customer-search', ['as'=>'order.customer-search','uses'=>'OrderController@search']);
Route::any('order/customer-selected', ['as'=>'order.customer-selected','uses'=>'OrderController@customerSelected']);
Route::any('order/ship_to_address_area', ['as'=>'order.ship_to_address_area','uses'=>'OrderController@ship_to_address_area']);
Route::any('order/dept_name_field', ['as'=>'order.dept_name_field','uses'=>'OrderController@dept_name_field']);

Route::any('equipment/create', ['as' => 'equipment.create', 'uses' => 'EquipmentController@create']);
Route::any('equipment/index', ['as' => 'equipment.index' , 'uses' => 'EquipmentController@index']);
Route::any('equipment/store', ['as' => 'equipment.store' , 'uses' => 'EquipmentController@store']);
Route::any('equipment/show/{id}', ['as' => 'equipment.show' , 'uses' => 'EquipmentController@show']);
Route::any('equipment/edit/{id}', ['as' => 'equipment.edit' , 'uses' => 'EquipmentController@edit']);
Route::any('equipment/update/{id}', ['as' => 'equipment.update' , 'uses' => 'EquipmentController@update']);
Route::any('equipment/destroy/{id}', ['as' => 'equipment.destroy' , 'uses' => 'EquipmentController@destroy']);
Route::any('equipment/loadManufacturer', ['as'=>'equipment.loadManufacturer','uses'=>'EquipmentController@loadManufacturer']);
Route::any('equipment/loadMachine', ['as'=>'equipment.loadMachine','uses'=>'EquipmentController@loadMachine']);
Route::any('equipment/loadModel', ['as'=>'equipment.loadModel','uses'=>'EquipmentController@loadModel']);
Route::any('equipment/loadImage', ['as'=>'equipment.loadImage','uses'=>'EquipmentController@loadImage']);});

The login page works its just the other routes that do not work. Sos, Order and Equipment.

I'm using php artisan serve



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1STOEJ5
via IFTTT