lundi 23 mai 2016

"creating default object from empty value" on update laravel 5

I'm new to Laravel and I'm getting this error message "creating default object from empty value". I'm supposed to update a current Facility but I'm not doing any good..Supposedly, when I click the SAVE button(edit_facilities.blade.php), it will update the data in the database but I think I'm doing it wrong..Can someone please help me on how to improve or correct my code..thanks. This is my CONTROLLER:

      <?php
      namespace App\Http\Controllers;

      use Illuminate\Http\Request;

      use App\Http\Requests;

      use App\Facilities;

      use View;

      use Redirect;

      use Alert;

      use Validator;

      use Input;

      use App\Providers\SweetAlertServiceProvider;

      class FacilitiesController extends Controller
      {

      public $restful = true;


      public function update_facilities($id){

        $facility = Facilities::find($id);

        $facility->facility_name = Input::get('facility_name');
        $facility->category      = Input::get('category');
        $facility->save();


        Alert::success('Successfully Updated', 'Congratulations');
        return view('hotelier/facilities');
      }?>

And this is my VIEW for view_facilities.blade.php:

<h2>Hotel Facilities</h2>
<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>Facility Name</th>
            <th>Category</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody id="facility_list">
        @foreach($facilities as $facility)
            <tr id="facility">
                <td></td>

                <td></td>

                <td><a href="<?php echo 'edit_facilities/'.$facility->id ?>" value="" class="btn btn-info open-modal">Edit</a>&nbsp;
                <a id="delete<?php echo $facility->id ?>" href="<?php echo 'delete_facilities/'.$facility->id ?>" class="btn btn-danger" onclick="delete_fac(this)" value="<?php echo $facility->facility_name ?>">Delete</a>&nbsp;

            </tr>
        @endforeach

    </tbody>
</table>

And this is for the VIEW of my edit_facilities.blade.php

<div class="container">
<h2>Edit Hotel Facility</h2>
<div class="col-md-4 form-horizontal">
    <form action="/update_facilities/'.$facility->id" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="_token" value="" />
        <label>Facility Name</label>
        <input type="text" class="form-control" value="" name="facility_name" id="facility_name" autocomplete="off"></input>
        <br />
        <label>Category</label>
        <input type="text" class="form-control" value="" name="category" id="category" autocomplete="off"></input>
        <br />
        <button type="submit" class="btn btn-info">Save</button>
    </form>
</div>

And my ROUTES:

Route::post('/update_facilities/{id}', 'FacilitiesController@update_facilities');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire