mercredi 24 juillet 2019

QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customers.id' in 'where clause'

I want to Edit my data in laravel system, which is have a customer_id as a increment key. But the error says,

Illuminate \ Database \ QueryException (42S22) SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customers.id' in 'where clause' (SQL: select * from customers where customers.id = 4 limit 1) Previous exceptions

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customers.id' in 'where clause' (42S22)

i dont understand why.

I've tried to add protected primarykey is customer_id in my model. but the result is same like before.

This is my Controller

    {
        $customer = \App\Customer_Model::find($customer_id);
        $customer->delete();
        return redirect('/customers')->with('sukses', 'Users has been deleted!');
    }

This is my model


namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer_Model extends Model
{
    protected $table = 'customers';
    protected $primarykey = 'customer_id';
    protected $fillable = ['customer_id', 'customer_code', 'customer_name', 'email', 'phone', 'contact_person', 'address', 'user_id', 'created_by', 'updated_by', 'void'];
}```

This is my view
```<tbody>
                      @foreach($data_customer as $cust)
                        <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><a href="/customers//edit" class="btn btn-warning"><span class="icon-settings icons icon"></span></a><a href="/customers//delete" class="btn btn-danger"><span class="icon-trash icons icon"></span></a></td>
                        </tr>
                        @endforeach
                      </tbody>```



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire