mercredi 24 mai 2017

Laravel 5.4 - Issue with query builder

I have a table called "Characters". Each row is identified by / has a primary key called char_id. I have routes and templates working as well as some controllers with some CRUD, so Laravel is working fine.

I want to be able to display a row, identified by the rows id, when a user goes to "character/{char_id}" eg "character/2".

I have the following code in my web route:

    Route::get('characters/{char_id}', function($char_id) {

        $character = \DB::table('characters')->find($char_id);
        dd($character);

});

But when I visit "characters/1" or any other number I get this error:

QueryException in Connection.php line 647:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `characters` where `id` = 1 limit 1)

It seems to be looking for a column called "id" regardless of what I try to pass from the URL. I'm following a tutorial that uses "id" so I suspect my code is looking for a column called "id" but I don't know how to get around that.



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

Aucun commentaire:

Enregistrer un commentaire