findOrFail Laravel 5 function for specific field findOrFail Laravel 5 function for specific field laravel laravel

findOrFail Laravel 5 function for specific field


You could create the behaviour you are looking for with the following:

Geo_Postal_us::where('postal', $postal)->firstOrFail();


Laravel by default is searching for the "id" column inside the table if you are using find(). To avoid running into errors here and maybe later, you should always tell laravel that you did take another name for your primary field.

To do that, in your Geo_Postal_us just edit as the following:

class Geo_Postal_us extends Model{      protected $primaryKey = 'postal'; //tell laravel to use 'postal' as primary key field......

I ran into this issue within Voyager and it really drove me nuts :).

Hope this helps some people as they google the issue.