سؤال

I would like to look up and return an object referenced by a different column to that of id.

As far as I know there isn't another method similar to Task::findOrFail($id) but that can reference another field. For example:

Task::findOrFail('column_name' = 'column_data');

I'm currently using

Task::where('tid' , '=', $tid)->first();

Is this possible?

هل كانت مفيدة؟

المحلول

Maybe you can use the firstOrFail() function of Laravel.

Task::where('column_name', '=' ,'column_data')->firstOrFail();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top